@Mapping(from = String.class, to = Application.class) public static Application map(String appName, Application template) { Application model = template != null ? template : new Application(); model.setName(appName); model.setId(GuidUtils.asGuid(appName.getBytes()).toString()); return model; } }
@Override public V3Application adapt(Application from) { V3Application to = new V3Application(); if (from.isSetLinks()) { to.getLinks().addAll(adaptOut(from.getLinks())); } if (from.isSetActions()) { to.setActions(adaptOut(from.getActions())); } if (from.isSetComment()) { to.setComment(from.getComment()); } if (from.isSetDescription()) { to.setDescription(from.getDescription()); } if (from.isSetId()) { to.setId(from.getId()); } if (from.isSetHref()) { to.setHref(from.getHref()); } if (from.isSetName()) { to.setName(from.getName()); } if (from.isSetVm()) { to.setVm(adaptOut(from.getVm())); } return to; } }
@Override public Application adapt(V3Application from) { Application to = new Application(); if (from.isSetLinks()) { to.getLinks().addAll(adaptIn(from.getLinks())); } if (from.isSetActions()) { to.setActions(adaptIn(from.getActions())); } if (from.isSetComment()) { to.setComment(from.getComment()); } if (from.isSetDescription()) { to.setDescription(from.getDescription()); } if (from.isSetId()) { to.setId(from.getId()); } if (from.isSetHref()) { to.setHref(from.getHref()); } if (from.isSetName()) { to.setName(from.getName()); } if (from.isSetVm()) { to.setVm(adaptIn(from.getVm())); } return to; } }
@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); }
private void verifyApplications(Applications applications) { assertNotNull(applications); assertEquals(NAMES.length, applications.getApplications().size()); int index = 0; for (Application app : applications.getApplications()) { assertEquals(NAMES[index], app.getName()); verifyLinks(app); index++; } }
/** * Create an instance of {@link Application } * */ public Application createApplication() { return new Application(); }
@Override public Application get() { Applications applications = parent.list(); for (Application app : applications.getApplications()) { if (app.getId().equals(id)) { return app; } } return notFound(); } }
@Test public void testGet() { setUriInfo(setUpBasicUriExpectations()); setUpEntityQueryExpectations(); Application application = resource.get(); assertEquals(NAMES[APPLICATION_INDEX], application.getName()); verifyLinks(application); }