JoltSpecBuilder { public static JoltSpec buildSpec(String jsonSpec) throws JoltSpecException { return buildSpec(jsonSpec, false); }  static JoltSpec buildSpec(String jsonSpec); static JoltSpec buildSpec(String jsonSpec, boolean withMetadata);  }
@Test public void testBuildSpecNull(TestContext context) throws JoltSpecException { thrown.expect( JoltSpecException.class ); thrown.expectCause(IsInstanceOf.instanceOf(NullPointerException.class)); JoltSpecBuilder.buildSpec(null); }
@Test public void testBuildSpecEmptyString(TestContext context) throws JoltSpecException { thrown.expect( JoltSpecException.class ); thrown.expectCause(IsInstanceOf.instanceOf(JsonUnmarshalException.class)); JoltSpecBuilder.buildSpec(""); }
@Test public void testBuildSpecEmptyJson(TestContext context) throws JoltSpecException { thrown.expect( JoltSpecException.class ); thrown.expectCause(IsInstanceOf.instanceOf(JsonUnmarshalException.class)); JoltSpecBuilder.buildSpec("{}"); }
@Test public void testBuildSpecNoJsonArray(TestContext context) throws JoltSpecException { thrown.expect( JoltSpecException.class ); thrown.expectCause(IsInstanceOf.instanceOf(JsonUnmarshalException.class)); JoltSpecBuilder.buildSpec("{\"abc\":234}"); }
@Test public void testBuildSpecMissingOperation(TestContext context) throws JoltSpecException { thrown.expect( JoltSpecException.class ); thrown.expectCause(IsInstanceOf.instanceOf(SpecException.class)); JoltSpecBuilder.buildSpec("[{\"abc\":234}]"); }
@Test public void testBuildSpecInvalidOperation(TestContext context) throws JoltSpecException { thrown.expect( JoltSpecException.class ); thrown.expectCause(IsInstanceOf.instanceOf(SpecException.class)); JoltSpecBuilder.buildSpec("[{\"operation\":\"xx\"}]"); }
@Test public void testBuildSpecMissingSpec(TestContext context) throws JoltSpecException { thrown.expect( JoltSpecException.class ); thrown.expectCause(IsInstanceOf.instanceOf(SpecException.class)); JoltSpecBuilder.buildSpec("[{\"operation\":\"shift\"}]"); }
@Test public void testBuildSpecInvalidSpecWrongType(TestContext context) throws JoltSpecException { thrown.expect( JoltSpecException.class ); thrown.expectCause(IsInstanceOf.instanceOf(SpecException.class)); String specWrongType = "[\n" + " {\n" + " \"operation\": \"shift\",\n" + " \"spec\": 123\n" + " }\n" + "]"; JoltSpecBuilder.buildSpec(specWrongType); }
@Test public void testBuildSpecInvalidSpecEmptyObject(TestContext context) throws JoltSpecException { thrown.expect( JoltSpecException.class ); thrown.expectCause(IsInstanceOf.instanceOf(SpecException.class)); String specEmptyObject = "[\n" + " {\n" + " \"operation\": \"shift\",\n" + " \"spec\": {}\n" + " }\n" + "]"; JoltSpecBuilder.buildSpec(specEmptyObject); }
@Test public void testBuildSpecInvalidSpecWildcardNotAllowed(TestContext context) throws JoltSpecException { thrown.expect( JoltSpecException.class ); thrown.expectCause(IsInstanceOf.instanceOf(SpecException.class)); String specWildcardNotAllowed = "[\n" + " {\n" + " \"operation\": \"shift\",\n" + " \"spec\": {\n" + " \"@1\": {\n" + " \"@\": \"*\"\n" + " }\n" + " }\n" + " }\n" + "]"; JoltSpecBuilder.buildSpec(specWildcardNotAllowed); }
@Test public void testBuildSpecValidSpec(TestContext context) throws JoltSpecException { String specValid = "[\n" + " {\n" + " \"operation\": \"shift\",\n" + " \"spec\": {\n" + " \"@\": \"\"\n" + " }\n" + " }\n" + "]"; JoltSpec joltSpec = JoltSpecBuilder.buildSpec(specValid); context.assertNotNull(joltSpec); context.assertNotNull(joltSpec.getChainr()); }
@Test public void testBuildSpecValidSpecWithMetadata(TestContext context) throws JoltSpecException { String specValid = "[\n" + " {\n" + " \"operation\": \"shift\",\n" + " \"spec\": {\n" + " \"@\": \"\"\n" + " }\n" + " }\n" + "]"; JoltSpec joltSpec = JoltSpecBuilder.buildSpec(specValid, true); context.assertNotNull(joltSpec); context.assertNotNull(joltSpec.getChainr()); context.assertTrue(joltSpec.isWithMetadata()); JoltSpec joltSpec2 = JoltSpecBuilder.buildSpec(specValid, false); context.assertNotNull(joltSpec2); context.assertNotNull(joltSpec2.getChainr()); context.assertFalse(joltSpec2.isWithMetadata()); }