@Test public void testGetProfile() throws Exception { String said = "12345"; URL baseUrl = new URL("http: String path = "/api/dime/rest/:target/shared/profile".replace(":target", said); String json = "[{`@context`:{`nco`:`http: URI profileUri = new URIImpl("urn:uuid:3dcb73e4-399f-41af-b4f2-a8bb48c315a1"); URI phoneUri = new URIImpl("urn:uuid:e9e07fd8-f53f-453b-b2dc-307e04c4fb61"); URI nameUri = new URIImpl("urn:uuid:18e938b1-935d-4cb4-b763-3ca1d654305f"); AccountRegistrar mockRegistrar = Mockito.mock(AccountRegistrar.class); Mockito.when(mockRegistrar.resolve(said)).thenReturn(baseUrl); HttpRestProxy mockProxy = Mockito.mock(HttpRestProxy.class); Mockito.when(mockProxy.get(Mockito.eq(path), Mockito.anyMap())).thenReturn(json); ProxyFactory mockFactory = Mockito.mock(ProxyFactory.class); Mockito.when(mockFactory.createProxy(Mockito.eq(baseUrl), Mockito.anyString(), Mockito.anyString())).thenReturn(mockProxy); DimeServiceAdapter adapter = new DimeServiceAdapter("1"); adapter.setProxyFactory(mockFactory); adapter.setAccountRegistrar(mockRegistrar); PersonContact profile = adapter.getProfile(said, new Token("token", "secret")); Model metadata = profile.getModel(); assertEquals(profileUri, profile.asURI()); assertTrue(metadata.contains(profileUri, NCO.hasPersonName, nameUri)); assertTrue(metadata.contains(profileUri, NCO.hasPhoneNumber, phoneUri)); assertTrue(metadata.contains(nameUri, RDF.type, NCO.PersonName)); assertEquals("Ismael Rivera", ModelUtils.findObject(metadata, nameUri, NCO.fullname).asLiteral().getValue()); assertEquals("Ismael", ModelUtils.findObject(metadata, nameUri, NCO.nameGiven).asLiteral().getValue()); assertEquals("Rivera", ModelUtils.findObject(metadata, nameUri, NCO.nameFamily).asLiteral().getValue()); assertTrue(metadata.contains(phoneUri, RDF.type, NCO.PhoneNumber)); assertEquals("555-55-55", ModelUtils.findObject(metadata, phoneUri, NCO.phoneNumber).asLiteral().getValue()); }
public PersonContact getProfile(String targetSaidName, Token token) throws AttributeNotSupportedException, ServiceNotAvailableException { HttpRestProxy proxy = null; PersonContact profile = null; final String path = SHARED_PROFILE_PATH.replace(":target", targetSaidName); try { URL baseURL = accountRegistrar.resolve(targetSaidName); proxy = proxyFactory.createProxy(baseURL, token.getToken(), token.getSecret()); Map<String, String> headers = headers( "Accept", MediaType.APPLICATION_JSONLD); String response = proxy.get(path, headers); logger.info("GET "+path+" [username="+token.getToken()+", password="+token.getSecret()+"] responded with: "+response); profile = JSONLDUtils.deserialize(response, PersonContact.class); if (logger.isDebugEnabled()) { logger.debug("Profile metadata for "+path+" response is:\n"+profile.getModel().serialize(Syntax.Turtle)); } } catch (AccountCannotResolveException e) { throw new ServiceNotAvailableException("said not registered at dns: " + targetSaidName, e); } catch (JsonParseException e) { throw new ServiceNotAvailableException( "Could not process response from "+path+", invalid JSON returned: "+e.getMessage(), "SERV-100"); } catch (JsonMappingException e) { throw new ServiceNotAvailableException( "Could not process response, invalid JSON returned: "+e.getMessage(), "SERV-100"); } catch (Exception e) { throw new ServiceNotAvailableException("Unknown error occurred: "+e.getMessage(), e); } finally { if (proxy != null) { proxy.close(); } } return profile; }
DimeServiceAdapter extends ServiceAdapterBase implements InternalServiceAdapter { public PersonContact getProfile(String targetSaidName, Token token) throws AttributeNotSupportedException, ServiceNotAvailableException { HttpRestProxy proxy = null; PersonContact profile = null; final String path = SHARED_PROFILE_PATH.replace(":target", targetSaidName); try { URL baseURL = accountRegistrar.resolve(targetSaidName); proxy = proxyFactory.createProxy(baseURL, token.getToken(), token.getSecret()); Map<String, String> headers = headers( "Accept", MediaType.APPLICATION_JSONLD); String response = proxy.get(path, headers); logger.info("GET "+path+" [username="+token.getToken()+", password="+token.getSecret()+"] responded with: "+response); profile = JSONLDUtils.deserialize(response, PersonContact.class); if (logger.isDebugEnabled()) { logger.debug("Profile metadata for "+path+" response is:\n"+profile.getModel().serialize(Syntax.Turtle)); } } catch (AccountCannotResolveException e) { throw new ServiceNotAvailableException("said not registered at dns: " + targetSaidName, e); } catch (JsonParseException e) { throw new ServiceNotAvailableException( "Could not process response from "+path+", invalid JSON returned: "+e.getMessage(), "SERV-100"); } catch (JsonMappingException e) { throw new ServiceNotAvailableException( "Could not process response, invalid JSON returned: "+e.getMessage(), "SERV-100"); } catch (Exception e) { throw new ServiceNotAvailableException("Unknown error occurred: "+e.getMessage(), e); } finally { if (proxy != null) { proxy.close(); } } return profile; } }
DimeServiceAdapter extends ServiceAdapterBase implements InternalServiceAdapter { public PersonContact getProfile(String targetSaidName, Token token) throws AttributeNotSupportedException, ServiceNotAvailableException { HttpRestProxy proxy = null; PersonContact profile = null; final String path = SHARED_PROFILE_PATH.replace(":target", targetSaidName); try { URL baseURL = accountRegistrar.resolve(targetSaidName); proxy = proxyFactory.createProxy(baseURL, token.getToken(), token.getSecret()); Map<String, String> headers = headers( "Accept", MediaType.APPLICATION_JSONLD); String response = proxy.get(path, headers); logger.info("GET "+path+" [username="+token.getToken()+", password="+token.getSecret()+"] responded with: "+response); profile = JSONLDUtils.deserialize(response, PersonContact.class); if (logger.isDebugEnabled()) { logger.debug("Profile metadata for "+path+" response is:\n"+profile.getModel().serialize(Syntax.Turtle)); } } catch (AccountCannotResolveException e) { throw new ServiceNotAvailableException("said not registered at dns: " + targetSaidName, e); } catch (JsonParseException e) { throw new ServiceNotAvailableException( "Could not process response from "+path+", invalid JSON returned: "+e.getMessage(), "SERV-100"); } catch (JsonMappingException e) { throw new ServiceNotAvailableException( "Could not process response, invalid JSON returned: "+e.getMessage(), "SERV-100"); } catch (Exception e) { throw new ServiceNotAvailableException("Unknown error occurred: "+e.getMessage(), e); } finally { if (proxy != null) { proxy.close(); } } return profile; } DimeServiceAdapter(String identifier); }
DimeServiceAdapter extends ServiceAdapterBase implements InternalServiceAdapter { public PersonContact getProfile(String targetSaidName, Token token) throws AttributeNotSupportedException, ServiceNotAvailableException { HttpRestProxy proxy = null; PersonContact profile = null; final String path = SHARED_PROFILE_PATH.replace(":target", targetSaidName); try { URL baseURL = accountRegistrar.resolve(targetSaidName); proxy = proxyFactory.createProxy(baseURL, token.getToken(), token.getSecret()); Map<String, String> headers = headers( "Accept", MediaType.APPLICATION_JSONLD); String response = proxy.get(path, headers); logger.info("GET "+path+" [username="+token.getToken()+", password="+token.getSecret()+"] responded with: "+response); profile = JSONLDUtils.deserialize(response, PersonContact.class); if (logger.isDebugEnabled()) { logger.debug("Profile metadata for "+path+" response is:\n"+profile.getModel().serialize(Syntax.Turtle)); } } catch (AccountCannotResolveException e) { throw new ServiceNotAvailableException("said not registered at dns: " + targetSaidName, e); } catch (JsonParseException e) { throw new ServiceNotAvailableException( "Could not process response from "+path+", invalid JSON returned: "+e.getMessage(), "SERV-100"); } catch (JsonMappingException e) { throw new ServiceNotAvailableException( "Could not process response, invalid JSON returned: "+e.getMessage(), "SERV-100"); } catch (Exception e) { throw new ServiceNotAvailableException("Unknown error occurred: "+e.getMessage(), e); } finally { if (proxy != null) { proxy.close(); } } return profile; } DimeServiceAdapter(String identifier); void setProxyFactory(ProxyFactory proxyFactory); void setAccountRegistrar(AccountRegistrar accountRegistrar); void setPublicResolverService(HttpRestProxy publicResolverService); void setCredentialStore(CredentialStore credentialStore); void setPolicyManager(PolicyManager policyManager); @Override String getAdapterName(); Collection<T> get(String receiverSAID, String senderSAID,
			String attribute, Class<T> returnType, Tenant tenant); BinaryFile getBinary(String receiverSAID, String senderSAID,
			String resourceId, Tenant tenant); @Override void _set(String attribute, Object value); @Override Collection<T> search(String attribute,
			Resource values, Class<T> returnType); @Override Collection<T> search(Resource values,
			Class<T> returnType); PersonContact getProfile(String targetSaidName, Token token); Token getUserToken(String username, Tenant tenant); boolean confirmToken(Token token, Tenant tenant); @Override Boolean isConnected(); ServiceResponse[] getRaw(String attribute); @Override Collection<T> get(String attribute, Class<T> returnType); @Override void response(String attribute, Resource value); @Override void delete(String attribute); }
DimeServiceAdapter extends ServiceAdapterBase implements InternalServiceAdapter { public PersonContact getProfile(String targetSaidName, Token token) throws AttributeNotSupportedException, ServiceNotAvailableException { HttpRestProxy proxy = null; PersonContact profile = null; final String path = SHARED_PROFILE_PATH.replace(":target", targetSaidName); try { URL baseURL = accountRegistrar.resolve(targetSaidName); proxy = proxyFactory.createProxy(baseURL, token.getToken(), token.getSecret()); Map<String, String> headers = headers( "Accept", MediaType.APPLICATION_JSONLD); String response = proxy.get(path, headers); logger.info("GET "+path+" [username="+token.getToken()+", password="+token.getSecret()+"] responded with: "+response); profile = JSONLDUtils.deserialize(response, PersonContact.class); if (logger.isDebugEnabled()) { logger.debug("Profile metadata for "+path+" response is:\n"+profile.getModel().serialize(Syntax.Turtle)); } } catch (AccountCannotResolveException e) { throw new ServiceNotAvailableException("said not registered at dns: " + targetSaidName, e); } catch (JsonParseException e) { throw new ServiceNotAvailableException( "Could not process response from "+path+", invalid JSON returned: "+e.getMessage(), "SERV-100"); } catch (JsonMappingException e) { throw new ServiceNotAvailableException( "Could not process response, invalid JSON returned: "+e.getMessage(), "SERV-100"); } catch (Exception e) { throw new ServiceNotAvailableException("Unknown error occurred: "+e.getMessage(), e); } finally { if (proxy != null) { proxy.close(); } } return profile; } DimeServiceAdapter(String identifier); void setProxyFactory(ProxyFactory proxyFactory); void setAccountRegistrar(AccountRegistrar accountRegistrar); void setPublicResolverService(HttpRestProxy publicResolverService); void setCredentialStore(CredentialStore credentialStore); void setPolicyManager(PolicyManager policyManager); @Override String getAdapterName(); Collection<T> get(String receiverSAID, String senderSAID,
			String attribute, Class<T> returnType, Tenant tenant); BinaryFile getBinary(String receiverSAID, String senderSAID,
			String resourceId, Tenant tenant); @Override void _set(String attribute, Object value); @Override Collection<T> search(String attribute,
			Resource values, Class<T> returnType); @Override Collection<T> search(Resource values,
			Class<T> returnType); PersonContact getProfile(String targetSaidName, Token token); Token getUserToken(String username, Tenant tenant); boolean confirmToken(Token token, Tenant tenant); @Override Boolean isConnected(); ServiceResponse[] getRaw(String attribute); @Override Collection<T> get(String attribute, Class<T> returnType); @Override void response(String attribute, Resource value); @Override void delete(String attribute); static final String NAME; }