/** * @return a string representing the marshalled value, might be raw value produced by the marshaller but we can also * provide a valid marshalled value in cases we want provide the marshalled value in a more human readable fashion. * e.g. we can store the marshalled value in a file with formatting. * By default we look for a resource with name of the class T.marshalledValue located in the class path. * e.g. if he class is MyMarshaller, we look for a resource MyMarshallerTest.marshalledValue. */ public String getMarshalledValue() throws Exception { return readResource(".marshalledValue"); }
@Test public void testUnMarshall() throws Exception { T result = marshaller.unmarshal(getMarshalledValue()); assertEquals(getValue(), result); } }
@Test public void testMarshall() throws Exception { String marshalledValue = marshaller.marshal(getValue()); String marshallerOutput = getMarshallerOutput(); ObjectMapper objectMapper = new ObjectMapper(); Map<String, Object> marshalledValueMap = (Map<String, Object>)(objectMapper.readValue(marshalledValue, Map.class)); Map<String, Object> marshallerOutputMap = (Map<String, Object>)(objectMapper.readValue(marshallerOutput, Map.class)); assertEquals(marshallerOutputMap, marshalledValueMap); }
public String readResource(String extension) throws Exception { URL resource = this.getClass().getResource(getType().getSimpleName() + extension); if (resource == null) { throw new Exception("No resource was found for: " + getType().getCanonicalName() + extension); } return new String(Files.readAllBytes(Paths.get(resource.toURI()))); }
@Before public void setUp() { marshaller = createMarshaller(); }
@Test public void testUnMarshall() throws Exception { T result = marshaller.unmarshal(getMarshalledValue()); assertEquals(getValue(), result); } }
@Test public void testMarshall() throws Exception { String marshalledValue = marshaller.marshal(getValue()); assertEquals(getMarshallerOutput(), marshalledValue); }
public String readResource(String extension) throws Exception { URL resource = this.getClass().getResource(getType().getSimpleName() + extension); if (resource == null) { throw new Exception("No resource was found for: " + getType().getCanonicalName() + extension); } return new String(Files.readAllBytes(Paths.get(resource.toURI()))); }
@Before public void setUp() { marshaller = createMarshaller(); }
@Test public void testGetClass() { assertEquals(getType(), marshaller.getType()); }
/** * @return the raw expected returned value by the marshaller. * By default we look for a resource with name of the class T.marshallerOutput located in the class path. * e.g. if he class is MyMarshaller, we look for a resource MyMarshallerTest.marshallerOutput. */ public String getMarshallerOutput() throws Exception { return readResource(".marshallerOutput"); }
@Test public void testGetClass() { assertEquals(getType(), marshaller.getType()); }
/** * @return a string representing the marshalled value, might be raw value produced by the marshaller but we can also * provide a valid marshalled value in cases we want provide the marshalled value in a more human readable fashion. * e.g. we can store the marshalled value in a file with formatting. * By default we look for a resource with name of the class T.marshalledValue located in the class path. * e.g. if he class is MyMarshaller, we look for a resource MyMarshallerTest.marshalledValue. */ public String getMarshalledValue() throws Exception { return readResource(".marshalledValue"); }
/** * @return the raw expected returned value by the marshaller. * By default we look for a resource with name of the class T.marshallerOutput located in the class path. * e.g. if he class is MyMarshaller, we look for a resource MyMarshallerTest.marshallerOutput. */ public String getMarshallerOutput() throws Exception { return readResource(".marshallerOutput"); }