AdjunctResource extends AbstractBrooklynRestResource implements AdjunctApi { @Override public AdjunctDetail get(String application, String entityToken, String adjunctId) { Entity entity = brooklyn().getEntity(application, entityToken); EntityAdjunct adjunct = brooklyn().getAdjunct(entity, adjunctId); return AdjunctTransformer.adjunctDetail(entity, adjunct, ui.getBaseUriBuilder(), brooklyn()); }  @Override List<AdjunctSummary> list(String application, String entityToken, String adjunctType); @SuppressWarnings({ "rawtypes", "unchecked" }) @Override AdjunctDetail addAdjunct(String application, String entityToken, String adjunctTypeName, Map<String, String> config); @Override AdjunctDetail get(String application, String entityToken, String adjunctId); @Override Status getStatus(String application, String entityToken, String adjunctId); @Override Response start(String application, String entityToken, String adjunctId); @Override Response stop(String application, String entityToken, String adjunctId); @Override Response destroy(String application, String entityToken, String adjunctId); @Override List<ConfigSummary> listConfig(
            final String application, final String entityToken, final String adjunctToken); @Override Map<String, Object> batchConfigRead(String application, String entityToken, String adjunctToken); @Override String getConfig(String application, String entityToken, String adjunctToken, String configKeyName); @SuppressWarnings({ "unchecked", "rawtypes" }) @Override Response setConfig(String application, String entityToken, String adjunctToken, String configKeyName, Object value); @Override List<TaskSummary> listTasks(String applicationId, String entityId, String adjunctToken, int limit, Boolean recurse); @Override Response getIcon(String applicationId, String entityId, String adjunctToken);  }
@Test public void testListAdjuncts() throws Exception { Set<AdjunctSummary> adjuncts = client().path(ENDPOINT) .get(new GenericType<Set<AdjunctSummary>>() {}); AdjunctSummary initialPolicy = null; List<AdjunctSummary> others = MutableList.of(); for (AdjunctSummary adj : adjuncts) { if (adj.getId().equals(policyId)) { initialPolicy = adj; } else if (adj.getAdjunctType()==BrooklynObjectType.POLICY){ } else { others.add(adj); } } log.info("Non-policy adjuncts: "+others); Asserts.assertSize(others, 4); assertEquals(initialPolicy.getName(), RestMockSimplePolicy.class.getName()); }
@Test public void testGetDetail() throws Exception { AdjunctDetail policy = client().path(ENDPOINT+policyId) .get(AdjunctDetail.class); assertEquals(policy.getName(), RestMockSimplePolicy.class.getName()); }
@Test public void testGetNonExistentConfigReturns404() throws Exception { String invalidConfigName = "doesnotexist"; try { ConfigSummary summary = client().path(ENDPOINT + policyId + "/config/" + invalidConfigName) .get(ConfigSummary.class); fail("Should have thrown 404, but got "+summary); } catch (Exception e) { if (!e.toString().contains("404")) throw e; } }
@Test public void testGetDefaultValue() throws Exception { String configName = RestMockSimplePolicy.SAMPLE_CONFIG.getName(); String expectedVal = RestMockSimplePolicy.SAMPLE_CONFIG.getDefaultValue(); String configVal = client().path(ENDPOINT + policyId + "/config/" + configName) .get(String.class); assertEquals(configVal, expectedVal); }
@Test(dependsOnMethods = "testReconfigureConfig") public void testGetConfigValue() throws Exception { String configName = RestMockSimplePolicy.SAMPLE_CONFIG.getName(); String expectedVal = "newval"; Map<String, Object> allState = client().path(ENDPOINT + policyId + "/config-current") .get(new GenericType<Map<String, Object>>() {}); assertEquals(allState, ImmutableMap.of(configName, expectedVal)); String configVal = client().path(ENDPOINT + policyId + "/config/" + configName) .get(String.class); assertEquals(configVal, expectedVal); }
@Test public void testHighlights() throws Exception { Set<AdjunctSummary> policies = client().path(ENDPOINT) .query("adjunctType", "policy") .get(new GenericType<Set<AdjunctSummary>>() {}); assertEquals(policies.size(), 1); AdjunctSummary policySummary = policies.iterator().next(); Map<String, HighlightTuple> highlights = policySummary.getHighlights(); assertEquals(highlights.size(), 2); HighlightTuple highlightTupleTask = highlights.get("testNameTask"); assertEquals(highlightTupleTask.getDescription(), "testDescription"); assertEquals(highlightTupleTask.getTime(), 123L); assertEquals(highlightTupleTask.getTaskId(), "testTaskId"); HighlightTuple highlightTupleNoTask = highlights.get("testNameNoTask"); assertEquals(highlightTupleNoTask.getDescription(), "testDescription"); assertEquals(highlightTupleNoTask.getTime(), 123L); assertEquals(highlightTupleNoTask.getTaskId(), null); }