@Test public void testGetArtifact() { final DbArtifact dbArtifact = new DbArtifact(); dbArtifact.setGroupId("groupId"); dbArtifact.setArtifactId("artifactId"); dbArtifact.setVersion("1.0.0-SNAPSHOT"); dbArtifact.setClassifier("win"); dbArtifact.setType("component"); dbArtifact.setExtension("jar"); dbArtifact.setDownloadUrl("nowhere"); dbArtifact.setSize("10Mo"); dbArtifact.setProvider("provider"); final DbLicense license = new DbLicense(); license.setName("licenseId"); dbArtifact.addLicense(license); final ModelMapper modelMapper = new ModelMapper(mock(RepositoryHandler.class)); final Artifact artifact = modelMapper.getArtifact(dbArtifact); assertEquals(dbArtifact.getGroupId(), artifact.getGroupId()); assertEquals(dbArtifact.getArtifactId(), artifact.getArtifactId()); assertEquals(dbArtifact.getVersion(), artifact.getVersion()); assertEquals(dbArtifact.getClassifier(), artifact.getClassifier()); assertEquals(dbArtifact.getType(), artifact.getType()); assertEquals(dbArtifact.getExtension(), artifact.getExtension()); assertEquals(dbArtifact.getSize(), artifact.getSize()); assertEquals(dbArtifact.getDownloadUrl(), artifact.getDownloadUrl()); assertEquals(dbArtifact.getProvider(), artifact.getProvider()); assertEquals(1, artifact.getLicenses().size()); assertEquals("licenseId", artifact.getLicenses().get(0)); }
@Test public void testGetDbArtifact() { final Artifact artifact = DataModelFactory.createArtifact( "groupId", "artifactId", "version", "classifier", "type", "extension"); artifact.setSize("10Mo"); artifact.setDownloadUrl("http://www.nowhere.com"); artifact.setProvider("http://www.nowhere.com/provider"); final ModelMapper modelMapper = new ModelMapper(mock(RepositoryHandler.class)); final DbArtifact dbArtifact = modelMapper.getDbArtifact(artifact); assertEquals(artifact.getGroupId(), dbArtifact.getGroupId()); assertEquals(artifact.getArtifactId(), dbArtifact.getArtifactId()); assertEquals(artifact.getVersion(), dbArtifact.getVersion()); assertEquals(artifact.getClassifier(), dbArtifact.getClassifier()); assertEquals(artifact.getType(), dbArtifact.getType()); assertEquals(artifact.getExtension(), dbArtifact.getExtension()); assertEquals(artifact.getSize(), dbArtifact.getSize()); assertEquals(artifact.getDownloadUrl(), dbArtifact.getDownloadUrl()); assertEquals(artifact.getProvider(), dbArtifact.getProvider()); }
private ACLMessage handleTourGuideRequest(ACLMessage request) { AID tourGuide = request.getSender(); ArrayList<String> interests; try { interests = (ArrayList<String>) request.getContentObject(); // System.out.println(getName() + ": Will handle " + interests.size() + " interests. // (Successfully read message)"); } catch (UnreadableException e) { System.out.println( myAgent.getAID().getName() + ":ERROR Couldn't get interests. Will respond with an empty list..."); interests = new ArrayList<>(); } String conversationID = request.getConversationId(); ArrayList<Integer> ids = new ArrayList<>(); for (Artifact artifact : artifacts) for (String interest : interests) if (artifact.getGenre().contains(interest) || artifact.getType().equals(interest)) ids.add(artifact.getId()); ACLMessage response = new ACLMessage(ACLMessage.INFORM); response.addReceiver(tourGuide); response.setConversationId(conversationID); response.setOntology("get-artifact-ids"); try { response.setContentObject(ids); } catch (IOException e) { System.err.println( myAgent.getAID().getName() + ": Couldn't serialize the ID-list... Will cause problems with other agents."); } return response; // System.out.println(myAgent.getAID().getName() + ":Response message sent to TourGuide with " // + ids.size() + " IDs."); }