AmqpMessageDispatcherService extends BaseAmqpService { @EventListener(classes = TargetAssignDistributionSetEvent.class) protected void targetAssignDistributionSet(final TargetAssignDistributionSetEvent assignedEvent) { if (!shouldBeProcessed(assignedEvent)) { return; } LOG.debug("targetAssignDistributionSet retrieved. I will forward it to DMF broker."); distributionSetManagement.get(assignedEvent.getDistributionSetId()).ifPresent(ds -> { final Map<SoftwareModule, List<SoftwareModuleMetadata>> softwareModules = getSoftwareModulesWithMetadata( ds); targetManagement.getByControllerID(assignedEvent.getActions().keySet()).forEach( target -> sendUpdateMessageToTarget(assignedEvent.getActions().get(target.getControllerId()), target, softwareModules)); }); } protected  AmqpMessageDispatcherService(final RabbitTemplate rabbitTemplate,
            final AmqpMessageSenderService amqpSenderService, final ArtifactUrlHandler artifactUrlHandler,
            final SystemSecurityContext systemSecurityContext, final SystemManagement systemManagement,
            final TargetManagement targetManagement, final ServiceMatcher serviceMatcher,
            final DistributionSetManagement distributionSetManagement,
            final SoftwareModuleManagement softwareModuleManagement, final DeploymentManagement deploymentManagement);   }
@Test @Description("Verifies that download and install event with 3 software moduls and no artifacts works") public void testSendDownloadRequesWithSoftwareModulesAndNoArtifacts() { final DistributionSet createDistributionSet = testdataFactory .createDistributionSet(UUID.randomUUID().toString()); testdataFactory.addSoftwareModuleMetadata(createDistributionSet); final Action action = createAction(createDistributionSet); final TargetAssignDistributionSetEvent targetAssignDistributionSetEvent = new TargetAssignDistributionSetEvent( action, serviceMatcher.getServiceId()); amqpMessageDispatcherService.targetAssignDistributionSet(targetAssignDistributionSetEvent); final Message sendMessage = getCaptureAdressEvent(targetAssignDistributionSetEvent); final DmfDownloadAndUpdateRequest downloadAndUpdateRequest = assertDownloadAndInstallMessage(sendMessage, action.getId()); assertThat(createDistributionSet.getModules()).hasSameSizeAs(downloadAndUpdateRequest.getSoftwareModules()); assertThat(downloadAndUpdateRequest.getTargetSecurityToken()).isEqualTo(TEST_TOKEN); for (final org.eclipse.hawkbit.dmf.json.model.DmfSoftwareModule softwareModule : downloadAndUpdateRequest .getSoftwareModules()) { assertTrue("Artifact list for softwaremodule should be empty", softwareModule.getArtifacts().isEmpty()); assertThat(softwareModule.getMetadata()).containsExactly( new DmfMetadata(TestdataFactory.VISIBLE_SM_MD_KEY, TestdataFactory.VISIBLE_SM_MD_VALUE)); for (final SoftwareModule softwareModule2 : action.getDistributionSet().getModules()) { assertNotNull("Sofware module ID should be set", softwareModule.getModuleId()); if (!softwareModule.getModuleId().equals(softwareModule2.getId())) { continue; } assertEquals( "Software module type in event should be the same as the softwaremodule in the distribution set", softwareModule.getModuleType(), softwareModule2.getType().getKey()); assertEquals( "Software module version in event should be the same as the softwaremodule in the distribution set", softwareModule.getModuleVersion(), softwareModule2.getVersion()); } } }
@Test @Description("Verifies that download and install event with software modules and artifacts works") public void testSendDownloadRequest() { DistributionSet dsA = testdataFactory.createDistributionSet(UUID.randomUUID().toString()); SoftwareModule module = dsA.getModules().iterator().next(); final List<AbstractDbArtifact> receivedList = new ArrayList<>(); for (final Artifact artifact : testdataFactory.createArtifacts(module.getId())) { receivedList.add(new ArtifactFilesystem(new File("./test"), artifact.getSha1Hash(), new DbArtifactHash(artifact.getSha1Hash(), null, null), artifact.getSize(), null)); } module = softwareModuleManagement.get(module.getId()).get(); dsA = distributionSetManagement.get(dsA.getId()).get(); final Action action = createAction(dsA); Mockito.when(rabbitTemplate.convertSendAndReceive(any())).thenReturn(receivedList); final TargetAssignDistributionSetEvent targetAssignDistributionSetEvent = new TargetAssignDistributionSetEvent( action, serviceMatcher.getServiceId()); amqpMessageDispatcherService.targetAssignDistributionSet(targetAssignDistributionSetEvent); final Message sendMessage = getCaptureAdressEvent(targetAssignDistributionSetEvent); final DmfDownloadAndUpdateRequest downloadAndUpdateRequest = assertDownloadAndInstallMessage(sendMessage, action.getId()); assertEquals("DownloadAndUpdateRequest event should contains 3 software modules", 3, downloadAndUpdateRequest.getSoftwareModules().size()); assertThat(downloadAndUpdateRequest.getTargetSecurityToken()).isEqualTo(TEST_TOKEN); for (final org.eclipse.hawkbit.dmf.json.model.DmfSoftwareModule softwareModule : downloadAndUpdateRequest .getSoftwareModules()) { if (!softwareModule.getModuleId().equals(module.getId())) { continue; } assertThat(softwareModule.getArtifacts().size()).isEqualTo(module.getArtifacts().size()).isGreaterThan(0); module.getArtifacts().forEach(dbArtifact -> { final Optional<org.eclipse.hawkbit.dmf.json.model.DmfArtifact> found = softwareModule.getArtifacts() .stream().filter(dmfartifact -> dmfartifact.getFilename().equals(dbArtifact.getFilename())) .findAny(); assertThat(found).as("The artifact should exist in message").isPresent(); assertThat(found.get().getSize()).isEqualTo(dbArtifact.getSize()); assertThat(found.get().getHashes().getMd5()).isEqualTo(dbArtifact.getMd5Hash()); assertThat(found.get().getHashes().getSha1()).isEqualTo(dbArtifact.getSha1Hash()); }); } }