@Test public void getMetadataByEntityId() { ArgumentCaptor<URI> captor = ArgumentCaptor.forClass(URI.class); final Map<String, Object> map = new HashMap<String, Object>(); map.put("coin:oauth:secret", "hissecret"); map.put("coin:oauth:two_legged_allowed", Boolean.TRUE); when(restTemplate.getForObject((URI) anyObject(), eq(Map.class))).thenReturn(map); String result = janusRestClient.getMetadataByEntityId("foo").getOauthConsumerSecret(); assertEquals("hissecret", result); verify(restTemplate).getForObject(captor.capture(), eq(Map.class)); assertTrue("Query string should contain correct entityid", captor.getValue().getQuery().contains("entityid=foo")); assertTrue("Query string should contain correct method", captor.getValue().getQuery().contains("method=getMetadata")); assertTrue("Query string should contain correct metadata field names", captor.getValue().getQuery().contains ("coin:oauth:secret")); assertTrue("Query string should contain correct user", captor.getValue().getQuery().contains("userid=user")); }
@Override public EntityMetadata getMetadataByEntityId(String entityId) { Map<String, String> parameters = new HashMap<String, String>(); parameters.put("entityid", entityId); final Collection metadataAsStrings = CollectionUtils.collect(Arrays.asList(Metadata.values()), new Transformer() { @Override public Object transform(Object input) { return ((Metadata) input).val(); } }); parameters.put("keys", StringUtils.join(metadataAsStrings, ',')); URI signedUri; try { signedUri = sign("getMetadata", parameters); if (LOG.isTraceEnabled()) { LOG.trace("Signed Janus-request is: {}", signedUri); } @SuppressWarnings("unchecked") final Map<String, Object> restResponse = restTemplate.getForObject(signedUri, Map.class); Assert.notNull(restResponse, "Rest response from Janus should not be null"); if (LOG.isTraceEnabled()) { LOG.trace("Janus-request returned: {}", restResponse.toString()); } final EntityMetadata entityMetadata = EntityMetadata.fromMetadataMap(restResponse); entityMetadata.setAppEntityId(entityId); return entityMetadata; } catch (IOException e) { LOG.error("While doing Janus-request", e); } return null; }
JanusRestClient implements Janus { @Override public EntityMetadata getMetadataByEntityId(String entityId) { Map<String, String> parameters = new HashMap<String, String>(); parameters.put("entityid", entityId); final Collection metadataAsStrings = CollectionUtils.collect(Arrays.asList(Metadata.values()), new Transformer() { @Override public Object transform(Object input) { return ((Metadata) input).val(); } }); parameters.put("keys", StringUtils.join(metadataAsStrings, ',')); URI signedUri; try { signedUri = sign("getMetadata", parameters); if (LOG.isTraceEnabled()) { LOG.trace("Signed Janus-request is: {}", signedUri); } @SuppressWarnings("unchecked") final Map<String, Object> restResponse = restTemplate.getForObject(signedUri, Map.class); Assert.notNull(restResponse, "Rest response from Janus should not be null"); if (LOG.isTraceEnabled()) { LOG.trace("Janus-request returned: {}", restResponse.toString()); } final EntityMetadata entityMetadata = EntityMetadata.fromMetadataMap(restResponse); entityMetadata.setAppEntityId(entityId); return entityMetadata; } catch (IOException e) { LOG.error("While doing Janus-request", e); } return null; } }
JanusRestClient implements Janus { @Override public EntityMetadata getMetadataByEntityId(String entityId) { Map<String, String> parameters = new HashMap<String, String>(); parameters.put("entityid", entityId); final Collection metadataAsStrings = CollectionUtils.collect(Arrays.asList(Metadata.values()), new Transformer() { @Override public Object transform(Object input) { return ((Metadata) input).val(); } }); parameters.put("keys", StringUtils.join(metadataAsStrings, ',')); URI signedUri; try { signedUri = sign("getMetadata", parameters); if (LOG.isTraceEnabled()) { LOG.trace("Signed Janus-request is: {}", signedUri); } @SuppressWarnings("unchecked") final Map<String, Object> restResponse = restTemplate.getForObject(signedUri, Map.class); Assert.notNull(restResponse, "Rest response from Janus should not be null"); if (LOG.isTraceEnabled()) { LOG.trace("Janus-request returned: {}", restResponse.toString()); } final EntityMetadata entityMetadata = EntityMetadata.fromMetadataMap(restResponse); entityMetadata.setAppEntityId(entityId); return entityMetadata; } catch (IOException e) { LOG.error("While doing Janus-request", e); } return null; } JanusRestClient(); }
JanusRestClient implements Janus { @Override public EntityMetadata getMetadataByEntityId(String entityId) { Map<String, String> parameters = new HashMap<String, String>(); parameters.put("entityid", entityId); final Collection metadataAsStrings = CollectionUtils.collect(Arrays.asList(Metadata.values()), new Transformer() { @Override public Object transform(Object input) { return ((Metadata) input).val(); } }); parameters.put("keys", StringUtils.join(metadataAsStrings, ',')); URI signedUri; try { signedUri = sign("getMetadata", parameters); if (LOG.isTraceEnabled()) { LOG.trace("Signed Janus-request is: {}", signedUri); } @SuppressWarnings("unchecked") final Map<String, Object> restResponse = restTemplate.getForObject(signedUri, Map.class); Assert.notNull(restResponse, "Rest response from Janus should not be null"); if (LOG.isTraceEnabled()) { LOG.trace("Janus-request returned: {}", restResponse.toString()); } final EntityMetadata entityMetadata = EntityMetadata.fromMetadataMap(restResponse); entityMetadata.setAppEntityId(entityId); return entityMetadata; } catch (IOException e) { LOG.error("While doing Janus-request", e); } return null; } JanusRestClient(); @Override EntityMetadata getMetadataByEntityId(String entityId); @Override List<String> getEntityIdsByMetaData(Metadata key, String value); @Override List<String> getAllowedSps(String idpentityid); @Override List<String> getAllowedSps(String idpentityid, String revision); @Override List<EntityMetadata> getSpList(); @Override List<EntityMetadata> getIdpList(); @Override ARP getArp(String entityId); @Override boolean isConnectionAllowed(String spEntityId, String idpEntityId); @Override JanusEntity getEntity(String entityId); void setRestTemplate(RestTemplate restTemplate); void setJanusUri(URI janusUri); void setUser(String user); void setSecret(String secret); }
JanusRestClient implements Janus { @Override public EntityMetadata getMetadataByEntityId(String entityId) { Map<String, String> parameters = new HashMap<String, String>(); parameters.put("entityid", entityId); final Collection metadataAsStrings = CollectionUtils.collect(Arrays.asList(Metadata.values()), new Transformer() { @Override public Object transform(Object input) { return ((Metadata) input).val(); } }); parameters.put("keys", StringUtils.join(metadataAsStrings, ',')); URI signedUri; try { signedUri = sign("getMetadata", parameters); if (LOG.isTraceEnabled()) { LOG.trace("Signed Janus-request is: {}", signedUri); } @SuppressWarnings("unchecked") final Map<String, Object> restResponse = restTemplate.getForObject(signedUri, Map.class); Assert.notNull(restResponse, "Rest response from Janus should not be null"); if (LOG.isTraceEnabled()) { LOG.trace("Janus-request returned: {}", restResponse.toString()); } final EntityMetadata entityMetadata = EntityMetadata.fromMetadataMap(restResponse); entityMetadata.setAppEntityId(entityId); return entityMetadata; } catch (IOException e) { LOG.error("While doing Janus-request", e); } return null; } JanusRestClient(); @Override EntityMetadata getMetadataByEntityId(String entityId); @Override List<String> getEntityIdsByMetaData(Metadata key, String value); @Override List<String> getAllowedSps(String idpentityid); @Override List<String> getAllowedSps(String idpentityid, String revision); @Override List<EntityMetadata> getSpList(); @Override List<EntityMetadata> getIdpList(); @Override ARP getArp(String entityId); @Override boolean isConnectionAllowed(String spEntityId, String idpEntityId); @Override JanusEntity getEntity(String entityId); void setRestTemplate(RestTemplate restTemplate); void setJanusUri(URI janusUri); void setUser(String user); void setSecret(String secret);  }