Search in sources :

Example 6 with Jsonb

use of jakarta.json.bind.Jsonb in project org.openntf.xsp.jakartaee by OpenNTF.

the class TestJsonb method testExampleBean.

@Test
public void testExampleBean() {
    Jsonb jsonb = JsonbBuilder.create();
    ExampleBean bean = new ExampleBean();
    bean.setFoo("hello");
    bean.setBar("world");
    String json = JSONBindUtil.toJson(bean, jsonb);
    assertEquals("Serialized bean should match expected", "{\"bar\":\"world\",\"foo\":\"hello\"}", json);
    ExampleBean bean2 = JSONBindUtil.fromJson(json, jsonb, ExampleBean.class);
    assertEquals("Beans should be equivalent", bean, bean2);
}
Also used : Jsonb(jakarta.json.bind.Jsonb) Test(org.junit.Test)

Example 7 with Jsonb

use of jakarta.json.bind.Jsonb in project zilla by aklivity.

the class ZpmSettingsTest method shouldWriteCredential.

@Test
public void shouldWriteCredential() {
    String expected = "{" + "\"credentials\":" + "[" + "{" + "\"host\":\"repo1.maven.org\"," + "\"password\":\"pass\"," + "\"realm\":\"HTTP Realm\"," + "\"username\":\"user\"" + "}" + "]" + "}";
    ZpmSettings settings = new ZpmSettings();
    settings.credentials = Collections.singletonList(new ZpmCredentials("HTTP Realm", "repo1.maven.org", "user", "pass"));
    Jsonb builder = JsonbBuilder.create();
    String actual = builder.toJson(settings);
    assertEquals(expected, actual);
}
Also used : Jsonb(jakarta.json.bind.Jsonb) Test(org.junit.Test)

Example 8 with Jsonb

use of jakarta.json.bind.Jsonb in project zilla by aklivity.

the class ZpmSettingsTest method shouldReadCredentials.

@Test
public void shouldReadCredentials() {
    String text = "{" + "\"credentials\":" + "[" + "{" + "\"realm\": \"HTTP Realm\"," + "\"host\": \"repo1.maven.org\"," + "\"username\": \"user\"," + "\"password\": \"pass\"" + "}," + "{" + "\"realm\": \"HTTP Realm 2\"," + "\"host\": \"repo2.maven.org\"," + "\"username\": \"user2\"," + "\"password\": \"pass2\"" + "}" + "]" + "}";
    Jsonb builder = JsonbBuilder.create();
    ZpmSettings settings = builder.fromJson(text, ZpmSettings.class);
    assertThat(settings, not(nullValue()));
    assertThat(settings.credentials, not(nullValue()));
    assertThat(settings.credentials, equalTo(asList(new ZpmCredentials("HTTP Realm", "repo1.maven.org", "user", "pass"), new ZpmCredentials("HTTP Realm 2", "repo2.maven.org", "user2", "pass2"))));
}
Also used : Jsonb(jakarta.json.bind.Jsonb) Test(org.junit.Test)

Example 9 with Jsonb

use of jakarta.json.bind.Jsonb in project zilla by aklivity.

the class ZpmConfigurationTest method shouldWriteRepositories.

@Test
public void shouldWriteRepositories() {
    String expected = "{" + "\"repositories\":" + "[" + "\"https://maven.example.com/maven2/\"," + "\"https://repo1.maven.org/maven2/\"" + "]" + "}";
    ZpmConfiguration config = new ZpmConfiguration();
    config.repositories = Arrays.asList(new ZpmRepository("https://maven.example.com/maven2/"), new ZpmRepository("https://repo1.maven.org/maven2/"));
    Jsonb builder = JsonbBuilder.create();
    String actual = builder.toJson(config);
    assertEquals(expected, actual);
}
Also used : Jsonb(jakarta.json.bind.Jsonb) Test(org.junit.Test)

Example 10 with Jsonb

use of jakarta.json.bind.Jsonb in project zilla by aklivity.

the class ZpmConfigurationTest method shouldReadDependency.

@Test
public void shouldReadDependency() {
    String text = "{" + "\"dependencies\":" + "[" + "\"io.aklivity.zilla:engine:1.0.0\"" + "]" + "}";
    Jsonb builder = JsonbBuilder.create();
    ZpmConfiguration config = builder.fromJson(text, ZpmConfiguration.class);
    assertThat(config, not(nullValue()));
    assertThat(config.dependencies, equalTo(singletonList(new ZpmDependency("io.aklivity.zilla", "engine", "1.0.0"))));
}
Also used : Jsonb(jakarta.json.bind.Jsonb) Test(org.junit.Test)

Aggregations

Jsonb (jakarta.json.bind.Jsonb)50 Test (org.junit.Test)28 JsonbConfig (jakarta.json.bind.JsonbConfig)12 Test (org.junit.jupiter.api.Test)6 InputStream (java.io.InputStream)4 Files.newInputStream (java.nio.file.Files.newInputStream)3 Path (java.nio.file.Path)3 ZpmSecurity (io.aklivity.zilla.manager.internal.settings.ZpmSecurity)2 Annot8ComponentDescriptor (io.annot8.api.components.Annot8ComponentDescriptor)2 Descriptor (io.annot8.common.serialization.TestNested.Descriptor)2 OutputStream (java.io.OutputStream)2 Files.newOutputStream (java.nio.file.Files.newOutputStream)2 ZpmCredentials (io.aklivity.zilla.manager.internal.settings.ZpmCredentials)1 ZpmSettings (io.aklivity.zilla.manager.internal.settings.ZpmSettings)1 Engine (io.aklivity.zilla.runtime.engine.Engine)1 EngineConfiguration (io.aklivity.zilla.runtime.engine.EngineConfiguration)1 BindingConfig (io.aklivity.zilla.runtime.engine.config.BindingConfig)1 NamespaceConfig (io.aklivity.zilla.runtime.engine.config.NamespaceConfig)1 RouteConfig (io.aklivity.zilla.runtime.engine.config.RouteConfig)1 VaultConfig (io.aklivity.zilla.runtime.engine.config.VaultConfig)1