-
Notifications
You must be signed in to change notification settings - Fork 276
/
Copy pathRegistryMojoWithMinifyTest.java
65 lines (53 loc) · 2.92 KB
/
RegistryMojoWithMinifyTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package io.apicurio.registry.noprofile.maven;
import io.apicurio.registry.maven.RegisterArtifact;
import io.apicurio.registry.maven.RegisterRegistryMojo;
import io.apicurio.registry.types.ArtifactType;
import io.apicurio.registry.utils.tests.TestUtils;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.io.File;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.List;
@QuarkusTest
public class RegistryMojoWithMinifyTest extends RegistryMojoTestBase {
RegisterRegistryMojo registerMojo;
@BeforeEach
public void createMojo() {
this.registerMojo = new RegisterRegistryMojo();
this.registerMojo.setRegistryUrl(TestUtils.getRegistryV3ApiUrl(testPort));
}
@Test
public void testMinify() throws Exception {
String groupId = "RegisterWithMinifyRegistryMojoTest";
File avroFile = new File(getClass().getResource("avro.avsc").getFile());
RegisterArtifact avroMinifiedArtifact = new RegisterArtifact();
avroMinifiedArtifact.setGroupId(groupId);
avroMinifiedArtifact.setArtifactId("userInfoMinified");
avroMinifiedArtifact.setType(ArtifactType.AVRO);
avroMinifiedArtifact.setMinify(true);
avroMinifiedArtifact.setFile(avroFile);
RegisterArtifact avroNotMinifiedArtifact = new RegisterArtifact();
avroNotMinifiedArtifact.setGroupId(groupId);
avroNotMinifiedArtifact.setArtifactId("userInfoNotMinified");
avroNotMinifiedArtifact.setType(ArtifactType.AVRO);
avroNotMinifiedArtifact.setFile(avroFile);
registerMojo.setArtifacts(List.of(avroMinifiedArtifact, avroNotMinifiedArtifact));
registerMojo.execute();
// Wait for the artifact to be created.
InputStream artifactInputStream = clientV3.groups().byGroupId(groupId).artifacts().byArtifactId("userInfoMinified").versions().byVersionExpression("branch=latest").content().get();
String artifactContent = new String(artifactInputStream.readAllBytes(), StandardCharsets.UTF_8);
Assertions.assertEquals("{\"type\":\"record\",\"name\":\"userInfo\",\"namespace\":\"my.example\",\"fields\":[{\"name\":\"age\",\"type\":\"int\"}]}", artifactContent);
// Wait for the artifact to be created.
artifactInputStream = clientV3.groups().byGroupId(groupId).artifacts().byArtifactId("userInfoNotMinified").versions().byVersionExpression("branch=latest").content().get();
artifactContent = new String(artifactInputStream.readAllBytes(), StandardCharsets.UTF_8);
Assertions.assertEquals("{\n" +
" \"type\" : \"record\",\n" +
" \"name\" : \"userInfo\",\n" +
" \"namespace\" : \"my.example\",\n" +
" \"fields\" : [{\"name\" : \"age\", \"type\" : \"int\"}]\n" +
"}", artifactContent);
}
}