private Mapper<org.ovirt.engine.api.model.Cluster, Cluster> getMapper() { MappingLocator mappingLocator = new MappingLocator(); mappingLocator.populate(); return mappingLocator.getMapper(org.ovirt.engine.api.model.Cluster.class, Cluster.class); }
private void init() { // Create and populate the message bundle: messageBundle = new MessageBundle(); messageBundle.setPath(Messages.class.getName()); messageBundle.populate(); // Create and populate the mapping locator: mappingLocator = new MappingLocator(); mappingLocator.populate(); }
protected <F, T> Mapper<F, T> getMapper(Class<F> from, Class<T> to) { return mappingLocator.getMapper(from, to); }
@BeforeEach public void setUp() { mappingLocator = new MappingLocator(); mappingLocator.populate(); }
protected <F, T> Mapper<F, T> getMapper(Class<F> from, Class<T> to) { return mapperLocator.getMapper(from, to); }
@BeforeEach public void setUp() { mappingLocator = new MappingLocator(PACKAGE_NAME); mappingLocator.populate(); }
@Test public void testSelfMapper() { Mapper<IFoo, IFoo> mapper = mappingLocator.getMapper(IFoo.class, IFoo.class); assertNull(mapper); } }
filterValue.add("false"); when(httpHeaders.getRequestHeader(USER_FILTER_HEADER)).thenReturn(filterValue); mapperLocator = new MappingLocator(); mapperLocator.populate(); locale = Locale.getDefault(); Locale.setDefault(Locale.GERMANY);
public static void setPayload(BackendResource resouce, Vm vm) { try { VmPayload payload = resouce.getEntity(VmPayload.class, QueryType.GetVmPayload, new IdQueryParameters(new Guid(vm.getId())), null, true); if (payload != null) { Payload p = resouce.getMappingLocator().getMapper(VmPayload.class, Payload.class).map(payload, null); Payloads payloads = new Payloads(); payloads.getPayloads().add(p); vm.setPayloads(payloads); } } catch(WebApplicationException ex) { if (ex.getResponse().getStatus()== Response.Status.NOT_FOUND.getStatusCode()) { //It's legal to not receive a payload for this VM, so the exception is caught and ignored. //(TODO: 'getEntity()' should be refactored to make it the programmer's decision, //whether to throw an exception or not in case the entity is not found.) Then //this try-catch won't be necessary. } else{ throw ex; } } }
@Test public void testRoundtrip() throws Exception { F model = fromClass.cast(populate(fromClass)); model = postPopulate(model); Mapper<F, T> out = mappingLocator.getMapper(fromClass, toClass); Mapper<I, F> back = mappingLocator.getMapper(inverseClass, fromClass); T to = out.map(model, null); I inverse = getInverse(to); F transform = back.map(inverse, getModel(null)); verify(model, transform); }
@Test @Override public void testRoundtrip() throws Exception { DiskSnapshot model = DiskSnapshot.class.cast(populate(DiskSnapshot.class)); model = postPopulate(model); Mapper<DiskSnapshot, Disk> out = getMappingLocator().getMapper(DiskSnapshot.class, Disk.class); Mapper<Disk, DiskSnapshot> back = getMappingLocator().getMapper(Disk.class, DiskSnapshot.class); DiskImage to = (DiskImage) out.map(model, null); DiskImage inverse = getInverse(to); DiskSnapshot transform = back.map(inverse, null); verify(model, transform); }
@Test @Override public void testRoundtrip() throws Exception { Disk model = Disk.class.cast(populate(Disk.class)); model = postPopulate(model); Mapper<Disk, org.ovirt.engine.core.common.businessentities.storage.Disk> out = getMappingLocator().getMapper(Disk.class, org.ovirt.engine.core.common.businessentities.storage.Disk.class); Mapper<org.ovirt.engine.core.common.businessentities.storage.Disk, Disk> back = getMappingLocator().getMapper(org.ovirt.engine.core.common.businessentities.storage.Disk.class, Disk.class); DiskImage to = (DiskImage) out.map(model, null); DiskImage inverse = getInverse(to); Disk transform = back.map(inverse, null); verify(model, transform); }
@Test @Override public void testRoundtrip() throws Exception { Disk model = Disk.class.cast(populate(Disk.class)); model = postPopulate(model); Mapper<Disk, org.ovirt.engine.core.common.businessentities.storage.Disk> out = getMappingLocator().getMapper(Disk.class, org.ovirt.engine.core.common.businessentities.storage.Disk.class); Mapper<org.ovirt.engine.core.common.businessentities.storage.Disk, Disk> back = getMappingLocator().getMapper(org.ovirt.engine.core.common.businessentities.storage.Disk.class, Disk.class); LunDisk to = (LunDisk) out.map(model, null); LunDisk inverse = getInverse(to); Disk transform = back.map(inverse, null); verify(model, transform); } }
@Test @Override public void testRoundtrip() throws Exception { Application model = Application.class.cast(populate(Application.class)); model = postPopulate(model); model.setName(NAMES[0]); model.setId(new Guid(NAMES[0].getBytes()).toString()); Mapper<String, Application> back = getMappingLocator().getMapper(String.class, Application.class); Application transform = back.map(NAMES[0], null); verify(model, transform); }
@Test public void testStaticBarToFooInterfaceMapper() { Mapper<IBar, IFoo> mapper = mappingLocator.getMapper(IBar.class, IFoo.class); assertNotNull(mapper); IFoo foo = mapper.map(new BarImpl("bar"), null); assertEquals("bar", foo.get()); }
@Test public void testStaticFooToBarInterfaceMapper() { Mapper<IFoo, IBar> mapper = mappingLocator.getMapper(IFoo.class, IBar.class); assertNotNull(mapper); IBar bar = mapper.map(new FooImpl("foo"), null); assertEquals("foo", bar.get()); }
@Test public void testStaticFooToBarClassMapper() { Mapper<FooImpl, BarImpl> mapper = mappingLocator.getMapper(FooImpl.class, BarImpl.class); assertNotNull(mapper); IBar bar = mapper.map(new FooImpl("foo"), null); assertEquals("foo", bar.get()); }
@Test public void testStaticBarToFooClassMapper() { Mapper<BarImpl, FooImpl> mapper = mappingLocator.getMapper(BarImpl.class, FooImpl.class); assertNotNull(mapper); IFoo foo = mapper.map(new BarImpl("bar"), null); assertEquals("bar", foo.get()); }
@Test public void testStaticTemplatedBarToFooClassMapper() { Mapper<BarImpl, FooImpl> mapper = mappingLocator.getMapper(BarImpl.class, FooImpl.class); assertNotNull(mapper); FooImpl foo = mapper.map(new BarImpl("bar"), new FooImpl("overwrite", "keep")); assertEquals("bar", foo.get()); assertEquals("keep", foo.other()); }
@Test public void testStaticTemplatedFooToBarClassMapper() { Mapper<FooImpl, BarImpl> mapper = mappingLocator.getMapper(FooImpl.class, BarImpl.class); assertNotNull(mapper); BarImpl bar = mapper.map(new FooImpl("foo"), new BarImpl("overwrite", "keep")); assertEquals("foo", bar.get()); assertEquals("keep", bar.other()); }