private <T> T deserialize(String content, Class<T> type) { if (type == null) { return null; } try { return MarshallerFactory.getMarshaller(MarshallingFormat.JSON, this.getClass().getClassLoader()).unmarshall(content, type); } catch ( MarshallingException e ) { throw new IllegalStateException( "Error while deserializing data received from server!", e ); } }
protected <T> T deserialize(String content, Class<T> type) { logger.debug("About to deserialize content: \n '{}' \n into type: '{}'", content, type); if (content == null || content.isEmpty()) { return null; } try { return marshaller.unmarshall(content, type); } catch ( MarshallingException e ) { throw new KieServicesException( "Error while deserializing data received from server!", e ); } }
private <T> T deserialize(String content, Class<T> type) { try { return marshaller.unmarshall( content, type ); } catch ( MarshallingException e ) { throw new KieServicesException( "Error while deserializing data received from server!", e ); } }
private void verifyMarshallingRoundTrip( Marshaller marshaller, Object inputObject ) { String rawContent = marshaller.marshall( inputObject ); logger.info(rawContent); Object testObjectAfterMarshallingTurnAround = marshaller.unmarshall( rawContent, inputObject.getClass() ); Assertions.assertThat( testObjectAfterMarshallingTurnAround ).isEqualTo( inputObject ); }
private void verifyMarshallingRoundTrip( Marshaller marshaller, Object inputObject ) { String rawContent = marshaller.marshall( inputObject ); Object testObjectAfterMarshallingTurnAround = marshaller.unmarshall( rawContent, inputObject.getClass() ); Assertions.assertThat( testObjectAfterMarshallingTurnAround ).isEqualTo( inputObject ); }
private void verifyMarshallingRoundTrip(Marshaller marshaller, Object inputObject) { String rawContent = marshaller.marshall(inputObject); Object testObjectAfterMarshallingTurnAround = marshaller.unmarshall(rawContent, inputObject.getClass()); Assertions.assertThat(inputObject).isEqualTo(testObjectAfterMarshallingTurnAround); }
@Test public void testUnmarshallListContainersCommandWithNoFilter() { String commandString = "<list-containers/>"; Marshaller marshaller = MarshallerFactory.getMarshaller(MarshallingFormat.XSTREAM, getClass().getClassLoader()); ListContainersCommand command = marshaller.unmarshall(commandString, ListContainersCommand.class); // the default ACCEPT_ALL filter should be set Assertions.assertThat(command.getKieContainerResourceFilter()).isEqualTo(KieContainerResourceFilter.ACCEPT_ALL); }
@Test public void testXStreamUnmarshalling() { final DMNContextKS result = xStreamMarshaller.unmarshall( XSTREAM, DMNContextKS.class ); checkBean(result); }
@Test public void testJsonUnmarshalling() { final DMNContextKS result = jsonMarshaller.unmarshall( JSON, DMNContextKS.class ); checkBean(result); }
private void assertForbiddenResponse(Response response) { assertNotNull(response); assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus()); ServiceResponse<?> serviceResponse = marshaller.unmarshall((String) response.getEntity(), ServiceResponse.class); assertNotNull(serviceResponse); assertEquals(ResponseType.FAILURE, serviceResponse.getType()); assertEquals("KIE Server management api is disabled", serviceResponse.getMsg()); } }
@Test public void testMarshallInsertObjectCommand() { String xmlCommand = "<insert>\n" + " <string>String value</string>\n" + "</insert>"; InsertObjectCommand command = marshaller.unmarshall( xmlCommand, InsertObjectCommand.class ); assertEquals( "String value", command.getObject().toString() ); assertEquals( xmlCommand, marshaller.marshall( command ) ); }
@Test public void testMarshallModifyCommand() { String xmlCommand = "<modify fact-handle=\"0:234:345:456:567:789\">\n" + " <set accessor=\"age\" value=\"30\"/>\n" + "</modify>"; ModifyCommand command = marshaller.unmarshall(xmlCommand, ModifyCommand.class); assertEquals(1, command.getSetters().size()); assertEquals("<modify fact-handle=\"0:234:345:456:567:789:NON_TRAIT\">\n" + " <set accessor=\"age\" value=\"30\"/>\n" + "</modify>", marshaller.marshall(command)); }
@Test public void testMarshallInsertElementsCommand() { String xmlCommand = "<insert-elements>\n" + " <string>test1</string>\n" + " <string>test2</string>\n" + "</insert-elements>"; InsertElementsCommand command = marshaller.unmarshall(xmlCommand, InsertElementsCommand.class); assertEquals(2, command.getObjects().size()); assertEquals(xmlCommand, marshaller.marshall(command)); }
@Test public void testMarshallFireAllRulesCommand() { String xmlCommand = "<fire-all-rules max=\"10\" out-identifier=\"result\"/>"; FireAllRulesCommand command = marshaller.unmarshall(xmlCommand, FireAllRulesCommand.class); assertEquals(10, command.getMax()); assertEquals(xmlCommand, marshaller.marshall(command)); }
@Test public void testMarshallGetObjectCommand() { String xmlCommand = "<get-object fact-handle=\"0:234:345:456:567:789\" out-identifier=\"test\"/>"; GetObjectCommand command = marshaller.unmarshall(xmlCommand, GetObjectCommand.class); assertEquals("test", command.getOutIdentifier()); assertEquals("<get-object fact-handle=\"0:234:345:456:567:789:NON_TRAIT\" out-identifier=\"test\"/>", marshaller.marshall(command)); }
@Test public void testMarshallStartProcessCommand() { String xmlCommand = "<start-process processId=\"org.drools.task.processOne\" out-identifier=\"id\"/>"; StartProcessCommand command = marshaller.unmarshall(xmlCommand, StartProcessCommand.class); assertEquals("org.drools.task.processOne", command.getProcessId()); assertEquals(xmlCommand, marshaller.marshall(command)); }
@Test public void testMarshallGetObjectsCommand() { String xmlCommand = "<get-objects out-identifier=\"objects\"/>"; GetObjectsCommand command = marshaller.unmarshall(xmlCommand, GetObjectsCommand.class); assertEquals("objects", command.getOutIdentifier()); assertEquals(xmlCommand, marshaller.marshall(command)); }
@Test @Ignore("Set focus command not yet supported") public void testMarshallAgendaGroupSetFocusCommand() { String xmlCommand = "<agenda-group-set-focus name=\"my-agenda-group\"/>"; AgendaGroupSetFocusCommand command = marshaller.unmarshall(xmlCommand, AgendaGroupSetFocusCommand.class); assertEquals("my-agenda-group", command.getName()); assertEquals(xmlCommand, marshaller.marshall(command)); }
@SuppressWarnings("unchecked") private <S extends Score<?>> S marshallUnmarshallScore(S toBeMarshalled) { ScoreWrapper wrapper = new ScoreWrapper(toBeMarshalled); SolverInstance instance = new SolverInstance(); instance.setScoreWrapper(wrapper); String marshalledSolver = marshaller.marshall(instance); SolverInstance result = marshaller.unmarshall(marshalledSolver, SolverInstance.class); return (S) result.getScoreWrapper().toScore(); } }
@Test public void testMarshallRetractCommand() { String xmlCommand = "<retract fact-handle=\"0:234:345:456:567:789\"/>"; DeleteCommand command = marshaller.unmarshall( xmlCommand, DeleteCommand.class ); assertEquals( "0:234:345:456:567:789:NON_TRAIT", command.getFactHandle().toExternalForm() ); assertEquals( "<retract fact-handle=\"0:234:345:456:567:789:NON_TRAIT\"/>", marshaller.marshall( command ) ); }