WidgetConfigResourceAssembler extends ResourceAssemblerSupport<WidgetConfig, WidgetConfigResource> { @Override public WidgetConfigResource toResource(WidgetConfig entity) { WidgetConfigResource resource = new WidgetConfigResource(); resource.setTitle(entity.getTitle()); resource.setType(entity.getType()); resource.setTitleUrl(entity.getTitleUrl()); resource.setDescription(entity.getDescription()); resource.setLastModified( Date.from(entity.getLastModified().atZone(ZoneId.systemDefault()).toInstant())); for (SourceConfig config : entity.getSourceConfigs()) { resource.getSourceConfigs().add(removeCredentials(config)); } resource.add( linkTo(methodOn(WidgetController.class).getWidget(dashboardSlug, entity.getId())) .withRel("self")); resource.add( linkTo(methodOn(DashboardController.class).getDashboard(dashboardSlug)) .withRel("dashboard")); resource.add( linkTo(methodOn(WidgetController.class).getData(dashboardSlug, entity.getId())) .withRel("data")); return resource; } WidgetConfigResourceAssembler(String dashboardSlug, String dashboardId); @Override WidgetConfigResource toResource(WidgetConfig entity); WidgetConfig toEntity(WidgetConfigResource resource);  }
@Test public void toResourceMasksUsername() { WidgetConfigResourceAssembler assembler = createAssembler(); WidgetConfigResource resource = assembler.toResource(createWidgetWithConfiguredUsername()); String username = extractConfigDataKey(resource, "username", String.class); assertThat(username).isEqualTo("**********"); }
@Test public void toResourceMasksPasswords() { WidgetConfigResourceAssembler assembler = createAssembler(); WidgetConfigResource resource = assembler.toResource(createWidgetWithConfiguredPassword()); String password = extractConfigDataKey(resource, "password", String.class); assertThat(password).isEqualTo("**********"); }
@Test public void toResourceMasksUsernameAndPassword() { WidgetConfigResourceAssembler assembler = createAssembler(); WidgetConfigResource resource = assembler.toResource(createWidgetWithConfiguredUsernameAndPassword()); String username = extractConfigDataKey(resource, "username", String.class); String password = extractConfigDataKey(resource, "password", String.class); assertThat(username).isEqualTo("**********"); assertThat(password).isEqualTo("**********"); }