/** * @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 testMarshall() throws Exception { String marshalledValue = marshaller.marshal(getValue()); assertEquals(getMarshallerOutput(), marshalledValue); }
@Test public void testUnMarshall() throws Exception { T result = marshaller.unmarshal(getMarshalledValue()); assertEquals(getValue(), result); } }
@Override public void testUnMarshall() throws Exception { PipelineExecutorTraceImpl result = marshaller.unmarshal(getMarshalledValue()); PipelineExecutorTraceImpl expectedValue = getValue(); assertEqualsPipelineExecutorTrace(expectedValue, result); }
@PostConstruct public void init() { marshallerInstance.iterator().forEachRemaining(marshaller -> { logger.debug("Registering marshaller into VFSMarshallerRegistry, marshaller: " + marshaller); register(marshaller.getType(), marshaller); }); } }
@Before public void setUp() { marshaller = createMarshaller(); }
@Before @Override public void setUp() { super.setUp(); List<Marshaller<?>> marshallers = new ArrayList<>(); when(marshallerInstance.iterator()).thenReturn(marshallers.iterator()); marshallerRegistry = new VFSMarshallerRegistry(marshallerInstance); ((VFSMarshallerRegistry) marshallerRegistry).init(); }
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()))); }
@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); }
@Test public void testUnMarshall() throws Exception { T result = marshaller.unmarshal(getMarshalledValue()); assertEquals(getValue(), result); } }
@Override public void testUnMarshall() throws Exception { PipelineExecutorTraceImpl result = marshaller.unmarshal(getMarshalledValue()); PipelineExecutorTraceImpl expectedValue = getValue(); assertEqualsPipelineExecutorTrace(expectedValue, result); }
/** * @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"); }
@Before public void setUp() { marshaller = createMarshaller(); }
@Before @Override public void setUp() { super.setUp(); List<Marshaller<?>> marshallers = new ArrayList<>(); when(marshallerInstance.iterator()).thenReturn(marshallers.iterator()); marshallerRegistry = new VFSMarshallerRegistry(marshallerInstance); ((VFSMarshallerRegistry) marshallerRegistry).init(); }
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()))); }
/** * Reads an Object previously marshalled and stored as a VFSRegistryEntry in a given path. * @param path the path where the VFSRegistryEntry is stored. * @return the unmarshalled object backed by the VFSRegistryEntry. * @throws Exception exceptions might be thrown in cases of filesystem or marshalling errors. */ public Object readEntry(final Path path) throws Exception { final String entryContent = ioService.readAllString(path); final VFSRegistryEntry entry = entryMarshaller.unmarshal(entryContent); final Marshaller marshaller = marshallerRegistry.get(Class.forName(entry.getContentType())); if (marshaller == null) { throw new Exception("No marshaller was found for class: " + entry.getContentType()); } return marshaller.unmarshal(entry.getContent()); }
/** * @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"); }
/** * @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"); }