@Consumes(MediaType.APPLICATION_JSON) @PUT public Response putNodeRoles(NodeRolesDataBean nodeRolesDataBean) throws IOException { checkClientArgument(nodeRolesDataBean != null, "Node roles must not be null"); checkClientArgument( noDuplicateDimensions(nodeRolesDataBean), "Supplied node roles contains duplicate dimensions"); if (!Main.getWorkMgr().putNetworkNodeRoles(nodeRolesDataBean.toNodeRolesData(), _network)) { return Response.status(Status.NOT_FOUND).build(); } return Response.ok().build(); } }
@Test public void testCheckClientArgumentTrue() { checkClientArgument(true, ""); } }
@POST public Response addNodeRoleDimension(NodeRoleDimensionBean dimBean) throws IOException { checkClientArgument(dimBean.name != null, "Node role dimension must have a name"); NodeRolesData nodeRolesData = Main.getWorkMgr().getNetworkNodeRoles(_network); if (nodeRolesData == null) { return Response.status(Status.NOT_FOUND).build(); } Optional<NodeRoleDimension> dimension = nodeRolesData.getNodeRoleDimension(dimBean.name); checkClientArgument(!dimension.isPresent(), "Duplicate dimension specified: %s", dimBean.name); if (!Main.getWorkMgr() .putNetworkNodeRoles( NodeRolesData.builder() .setDefaultDimension(nodeRolesData.getDefaultDimension()) .setRoleDimensions( ImmutableSortedSet.<NodeRoleDimension>naturalOrder() .addAll(nodeRolesData.getNodeRoleDimensions()) .add(dimBean.toNodeRoleDimension()) .build()) .build(), _network)) { // if network was deleted while we were working return Response.status(Status.NOT_FOUND).build(); } return Response.ok().build(); }
@Test public void testCheckClientArgumentFalseVarArgs() { _thrown.expect(BadRequestException.class); _thrown.expectMessage("varargs"); checkClientArgument(false, "%s%s", "var", "args"); }
@Test public void testCheckClientArgumentFalseNoVarArgs() { _thrown.expect(BadRequestException.class); _thrown.expectMessage("message"); checkClientArgument(false, "message"); }