|
2 | 2 |
|
3 | 3 | import io.apicurio.registry.model.GroupId;
|
4 | 4 | import io.apicurio.registry.rest.client.models.ArtifactReference;
|
| 5 | +import io.apicurio.registry.rest.client.models.ArtifactSearchResults; |
| 6 | +import io.apicurio.registry.rest.client.models.BranchMetaData; |
5 | 7 | import io.apicurio.registry.rest.client.models.HandleReferencesType;
|
| 8 | +import io.apicurio.registry.rest.client.models.ProblemDetails; |
| 9 | +import io.apicurio.registry.rest.client.models.VersionMetaData; |
6 | 10 | import io.apicurio.registry.storage.RegistryStorage;
|
7 | 11 | import io.apicurio.registry.types.Current;
|
8 | 12 | import io.apicurio.registry.utils.IoUtil;
|
@@ -152,4 +156,46 @@ public void testCheckJsonWithReferences() throws Exception {
|
152 | 156 | * HandleReferencesType.DEREFERENCE; }));
|
153 | 157 | */
|
154 | 158 | }
|
| 159 | + |
| 160 | + @Test |
| 161 | + public void testLatestBranch() { |
| 162 | + try { |
| 163 | + ArtifactSearchResults results = clientV3.search().artifacts().get(); |
| 164 | + results.getArtifacts().forEach(artifact -> { |
| 165 | + String groupId = "default"; |
| 166 | + if (artifact.getGroupId() != null) { |
| 167 | + groupId = artifact.getGroupId(); |
| 168 | + } |
| 169 | + BranchMetaData branchMetaData = clientV3.groups().byGroupId(groupId).artifacts() |
| 170 | + .byArtifactId(artifact.getArtifactId()).branches().byBranchId("latest").get(); |
| 171 | + Assertions.assertNotNull(branchMetaData); |
| 172 | + Assertions.assertEquals(artifact.getGroupId(), branchMetaData.getGroupId()); |
| 173 | + Assertions.assertEquals(artifact.getArtifactId(), branchMetaData.getArtifactId()); |
| 174 | + Assertions.assertEquals("latest", branchMetaData.getBranchId()); |
| 175 | + |
| 176 | + VersionMetaData versionMetaData = clientV3.groups().byGroupId(groupId).artifacts() |
| 177 | + .byArtifactId(artifact.getArtifactId()).versions() |
| 178 | + .byVersionExpression("branch=latest").get(); |
| 179 | + Assertions.assertNotNull(versionMetaData); |
| 180 | + Assertions.assertEquals(artifact.getGroupId(), versionMetaData.getGroupId()); |
| 181 | + Assertions.assertEquals(artifact.getArtifactId(), versionMetaData.getArtifactId()); |
| 182 | + }); |
| 183 | + |
| 184 | + // Make sure the latest version of "MixAvroExample/Farewell" is version "2" |
| 185 | + VersionMetaData versionMetaData = clientV3.groups().byGroupId("MixAvroExample").artifacts() |
| 186 | + .byArtifactId("Farewell").versions().byVersionExpression("branch=latest").get(); |
| 187 | + Assertions.assertNotNull(versionMetaData); |
| 188 | + Assertions.assertEquals("2", versionMetaData.getVersion()); |
| 189 | + |
| 190 | + // Make sure the latest version of "default/city" is version "2" |
| 191 | + versionMetaData = clientV3.groups().byGroupId("default").artifacts().byArtifactId("city") |
| 192 | + .versions().byVersionExpression("branch=latest").get(); |
| 193 | + Assertions.assertNotNull(versionMetaData); |
| 194 | + Assertions.assertEquals("2", versionMetaData.getVersion()); |
| 195 | + } catch (ProblemDetails e) { |
| 196 | + System.err.println("ERROR: " + e.getDetail()); |
| 197 | + throw e; |
| 198 | + } |
| 199 | + } |
| 200 | + |
155 | 201 | }
|
0 commit comments