ScreenService extends BasicService implements OwnerAPISupport<Screen> { @POST @Path("/screens/{id}/copy") @Consumes(MediaType.APPLICATION_JSON) public Screen copyScreen(@PathParam("id") long screenId, Screen newScreen) { Screen existingScreen = getExistingScreen(screenId, false); Screen copiedScreen = new Screen(existingScreen); copiedScreen.setName(newScreen.getName()); copiedScreen = createScreen(copiedScreen); return copiedScreen; }  @GET @Path("/screens") @Produces(MediaType.APPLICATION_JSON) List<Screen> getScreens(@QueryParam("userId") String userId); @GET @Path("/onboardings") @Produces(MediaType.APPLICATION_JSON) List<Screen> getOnboardings(); @GET @Path("/screens/{id}") @Produces(MediaType.APPLICATION_JSON) Screen getScreen(@PathParam("id") long screenId,
			@DefaultValue("true") @QueryParam("includeMetrics") boolean includeMetrics,
			@DefaultValue("false") @QueryParam("live") boolean live); @GET @Path("/screens/bykey/{key}") @Produces(MediaType.APPLICATION_JSON) Screen getScreenByKey(@PathParam("key") String key,
			@DefaultValue("true") @QueryParam("includeMetrics") boolean includeMetrics,
			@DefaultValue("false") @QueryParam("live") boolean live,
			@DefaultValue("false") @QueryParam("autoOnboard") boolean doOnboarding,
			@QueryParam("owner") String requestedOwner); @POST @Path("/screens") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) Screen createScreen(Screen screen); @PUT @Path("/screens/{id}") @Produces(MediaType.APPLICATION_JSON) Screen updateScreen(@PathParam("id") long screenId, Screen screenData); @PUT @Path("/screens/{id}/statistics") @Produces(MediaType.APPLICATION_JSON) Screen updateScreenStatstics(@PathParam("id") long screenId, Screen screenData); @GET @Path("/screens/{id}/health") @Produces(MediaType.APPLICATION_JSON) Screen.AliveState getScreenHealth(@PathParam("id") long screenId); @GET @Path("/screens/{id}/events") @Produces(MediaType.APPLICATION_JSON) List<EventHistory> getScreenEvents(@PathParam("id") long screenId); @GET @Path("/screens/{id}/eventsperhour") @Produces(MediaType.APPLICATION_JSON) List<BasicNameValuePair> getScreenEventsPerHour(@PathParam("id") long screenId); @GET @Path("/screens/{id}/control") @Produces(MediaType.APPLICATION_JSON) Integer getRemoteKey(@PathParam("id") long screenId); @PUT @Path("/screens/{id}/control/{key}") @Produces(MediaType.APPLICATION_JSON) Screen remoteControlScreen(@PathParam("id") long screenId, Screen screenData, @PathParam("key") int key); @POST @Path("/screens/{id}/copy") @Consumes(MediaType.APPLICATION_JSON) Screen copyScreen(@PathParam("id") long screenId, Screen newScreen); @PUT @Path("/screens/{id}/requestedOwner") @Produces(MediaType.APPLICATION_JSON) Screen updateRequestedOwner(@PathParam("id") long screenId, Screen screenData); @POST @Path("/screens/{id}/onboard") @Produces(MediaType.APPLICATION_JSON) Screen onboardScreen(@PathParam("id") long screenId); @POST @Path("/claim/{key}") @Produces(MediaType.APPLICATION_JSON) Screen claimScreen(@PathParam("key") String key, @DefaultValue("0") @QueryParam("screenId") long screenId); @DELETE @Path("/screens/{screenId}") Response deleteScreen(@PathParam("screenId") long screenId); @Override @POST @Path("/screens/{screenId}/owners") @Consumes(MediaType.APPLICATION_JSON) Screen addOwners(@PathParam("screenId") long screenId, Owner[] ownerData); @Override @DELETE @Path("/screens/{screenId}/owners/{ownerId}") @Produces(MediaType.APPLICATION_JSON) Screen deleteOwner(@PathParam("screenId") long screenId, @PathParam("ownerId") long ownerId); @POST @Path("/screenkey/{key}/appliancestart") @Consumes(MediaType.APPLICATION_JSON) Response registerApplianceStart(@PathParam("key") String key, ApplianceInfo logContent);  }
@Test public void testCopyScreen() throws Exception { Screen screen = screenService.createScreen(new Screen("s1")); screen = screenService.copyScreen(screen.getId(), new Screen("s2")); List<Screen> screens = getScreens(); assertEquals(2, screens.size()); assertEquals("s2", screens.get(1).getName()); assertEquals(screen.getId(), screens.get(1).getId()); }
@Test(expected = WebApplicationException.class) public void testCopyNonExistentScreens() throws Exception { screenService.copyScreen(-1, new Screen()); }