@SuppressWarnings("unchecked") @Test public void testUpdate() throws ApplicationServiceException, IOException { when(Config.applicationPersistenceService.updateApplication(any(UpdateApplicationRequest.class))) .thenReturn(Config.mockApplication2); Group group = mock(Group.class); when(Config.mockApplication2.getName()).thenReturn("test-app-name"); when(Config.mockApplication2.getWarName()).thenReturn("test-war-name"); when(Config.mockApplication2.getGroup()).thenReturn(group); when(group.getName()).thenReturn("group1"); long id = 22; JpaGroup jpaGroup = mock(JpaGroup.class); when(group.getId()).thenReturn(new Identifier<Group>(id)); List<Long> listOfIds = new ArrayList<>(); listOfIds.add((long) 22); List<JpaGroup> jpaGroups = new ArrayList<>(); jpaGroups.add(jpaGroup); when(Config.mockGroupPersistenceService.findGroups(listOfIds)).thenReturn(jpaGroups); JpaApplication jpaApplication = mock(JpaApplication.class); when(Config.applicationPersistenceService.getJpaApplication(Config.mockApplication2.getName())).thenReturn (jpaApplication); when(Config.mockGroupPersistenceService.getGroupAppResourceTemplateMetaData("group1", "test-war-name", "test-app-names")) .thenReturn ("{\"templateName\":\"test-template-name\", \"contentType\":\"application/zip\", \"deployFileName\":\"test-app.war\", \"deployPath\":\"/fake/deploy/path\", \"entity\":{}, \"unpack\":\"true\", \"overwrite\":\"true\"}"); when(Config.mockResourceService.getMetaData(anyString())).thenReturn(new ResourceTemplateMetaData("test-template-name", MediaType.APPLICATION_ZIP, "deploy-file-name", "deploy-path", null, true, false, null)); UpdateApplicationRequest cac = new UpdateApplicationRequest(Config.mockApplication2.getId(), Identifier.id(1L, Group.class), "wan", "/wan", true, true, false); Application created = applicationService.updateApplication(cac, new User("user")); assertTrue(created == Config.mockApplication2); verify(Config.mockGroupPersistenceService).updateGroupAppResourceMetaData(anyString(), anyString(), anyString(), anyString()); }
@Transactional @Override public Application updateApplication(UpdateApplicationRequest updateApplicationRequest, User anUpdatingUser) throws ApplicationServiceException{ updateApplicationRequest.validate(); final Application application = applicationPersistenceService.updateApplication(updateApplicationRequest); String appName = application.getName(); Identifier<Group> newGroupId = application.getGroup().getId(); Long id = newGroupId.getId(); List<Long> idList = Collections.singletonList(id); List<JpaGroup> jpaGroups = groupPersistenceService.findGroups(idList); if (jpaGroups.size() == 1) { JpaApplication jpaApp = applicationPersistenceService.getJpaApplication(appName); if (null != jpaApp.getWarName()) { resourceDao.updateResourceGroup(jpaApp, jpaGroups.get(0)); } } else { throw new ApplicationServiceException("One Jpa Group expected for the application."); } updateApplicationWarMetaData(updateApplicationRequest, application); return application; }
ApplicationServiceImpl implements ApplicationService { @Transactional @Override public Application updateApplication(UpdateApplicationRequest updateApplicationRequest, User anUpdatingUser) throws ApplicationServiceException{ updateApplicationRequest.validate(); final Application application = applicationPersistenceService.updateApplication(updateApplicationRequest); String appName = application.getName(); Identifier<Group> newGroupId = application.getGroup().getId(); Long id = newGroupId.getId(); List<Long> idList = Collections.singletonList(id); List<JpaGroup> jpaGroups = groupPersistenceService.findGroups(idList); if (jpaGroups.size() == 1) { JpaApplication jpaApp = applicationPersistenceService.getJpaApplication(appName); if (null != jpaApp.getWarName()) { resourceDao.updateResourceGroup(jpaApp, jpaGroups.get(0)); } } else { throw new ApplicationServiceException("One Jpa Group expected for the application."); } updateApplicationWarMetaData(updateApplicationRequest, application); return application; } }
ApplicationServiceImpl implements ApplicationService { @Transactional @Override public Application updateApplication(UpdateApplicationRequest updateApplicationRequest, User anUpdatingUser) throws ApplicationServiceException{ updateApplicationRequest.validate(); final Application application = applicationPersistenceService.updateApplication(updateApplicationRequest); String appName = application.getName(); Identifier<Group> newGroupId = application.getGroup().getId(); Long id = newGroupId.getId(); List<Long> idList = Collections.singletonList(id); List<JpaGroup> jpaGroups = groupPersistenceService.findGroups(idList); if (jpaGroups.size() == 1) { JpaApplication jpaApp = applicationPersistenceService.getJpaApplication(appName); if (null != jpaApp.getWarName()) { resourceDao.updateResourceGroup(jpaApp, jpaGroups.get(0)); } } else { throw new ApplicationServiceException("One Jpa Group expected for the application."); } updateApplicationWarMetaData(updateApplicationRequest, application); return application; } ApplicationServiceImpl(final ApplicationPersistenceService applicationPersistenceService,
                                  final JvmPersistenceService jvmPersistenceService,
                                  final GroupPersistenceService groupPersistenceService,
                                  final ResourceService resourceService,
                                  final BinaryDistributionService binaryDistributionService,
                                  final HistoryFacadeService historyFacadeService,
                                  final BinaryDistributionLockManager binaryDistributionLockManager); }
ApplicationServiceImpl implements ApplicationService { @Transactional @Override public Application updateApplication(UpdateApplicationRequest updateApplicationRequest, User anUpdatingUser) throws ApplicationServiceException{ updateApplicationRequest.validate(); final Application application = applicationPersistenceService.updateApplication(updateApplicationRequest); String appName = application.getName(); Identifier<Group> newGroupId = application.getGroup().getId(); Long id = newGroupId.getId(); List<Long> idList = Collections.singletonList(id); List<JpaGroup> jpaGroups = groupPersistenceService.findGroups(idList); if (jpaGroups.size() == 1) { JpaApplication jpaApp = applicationPersistenceService.getJpaApplication(appName); if (null != jpaApp.getWarName()) { resourceDao.updateResourceGroup(jpaApp, jpaGroups.get(0)); } } else { throw new ApplicationServiceException("One Jpa Group expected for the application."); } updateApplicationWarMetaData(updateApplicationRequest, application); return application; } ApplicationServiceImpl(final ApplicationPersistenceService applicationPersistenceService,
                                  final JvmPersistenceService jvmPersistenceService,
                                  final GroupPersistenceService groupPersistenceService,
                                  final ResourceService resourceService,
                                  final BinaryDistributionService binaryDistributionService,
                                  final HistoryFacadeService historyFacadeService,
                                  final BinaryDistributionLockManager binaryDistributionLockManager); @Transactional(readOnly = true) @Override Application getApplication(Identifier<Application> aApplicationId); @Transactional(readOnly = true) @Override Application getApplication(final String name); @Transactional(readOnly = true) @Override List<Application> getApplications(); @Transactional(readOnly = true) @Override List<Application> findApplications(Identifier<Group> groupId); @Transactional(readOnly = true) @Override List<Application> findApplicationsByJvmId(Identifier<Jvm> jvmId); @Transactional @Override Application updateApplication(UpdateApplicationRequest updateApplicationRequest, User anUpdatingUser); @Transactional @Override Application createApplication(final CreateApplicationRequest createApplicationRequest,
                                         final User aCreatingUser); @Transactional @Override void removeApplication(Identifier<Application> anAppIdToRemove, User user); @Override @Transactional(readOnly = true) List<String> getResourceTemplateNames(final String appName, final String jvmName); @Override @Transactional String updateResourceTemplate(final String appName, final String resourceTemplateName, final String template, final String jvmName, final String groupName); @Override @Transactional // TODO: Have an option to do a hot deploy or not. CommandOutput deployConf(final String appName, final String groupName, final String jvmName,
                                    final String resourceTemplateName, ResourceGroup resourceGroup, User user); @Override @Transactional JpaApplicationConfigTemplate uploadAppTemplate(UploadAppTemplateRequest uploadAppTemplateRequest); @Override @Transactional String previewResourceTemplate(String fileName, String appName, String groupName, String jvmName, String template, ResourceGroup resourceGroup); @Override @Transactional void copyApplicationWarToGroupHosts(Application application); @Override void deployApplicationResourcesToGroupHosts(String groupName, Application app, ResourceGroup resourceGroup); @Override @Transactional void copyApplicationWarToHost(Application application, String hostName); @Override void deployConf(final String appName, final String hostName, final User user); }
ApplicationServiceImpl implements ApplicationService { @Transactional @Override public Application updateApplication(UpdateApplicationRequest updateApplicationRequest, User anUpdatingUser) throws ApplicationServiceException{ updateApplicationRequest.validate(); final Application application = applicationPersistenceService.updateApplication(updateApplicationRequest); String appName = application.getName(); Identifier<Group> newGroupId = application.getGroup().getId(); Long id = newGroupId.getId(); List<Long> idList = Collections.singletonList(id); List<JpaGroup> jpaGroups = groupPersistenceService.findGroups(idList); if (jpaGroups.size() == 1) { JpaApplication jpaApp = applicationPersistenceService.getJpaApplication(appName); if (null != jpaApp.getWarName()) { resourceDao.updateResourceGroup(jpaApp, jpaGroups.get(0)); } } else { throw new ApplicationServiceException("One Jpa Group expected for the application."); } updateApplicationWarMetaData(updateApplicationRequest, application); return application; } ApplicationServiceImpl(final ApplicationPersistenceService applicationPersistenceService,
                                  final JvmPersistenceService jvmPersistenceService,
                                  final GroupPersistenceService groupPersistenceService,
                                  final ResourceService resourceService,
                                  final BinaryDistributionService binaryDistributionService,
                                  final HistoryFacadeService historyFacadeService,
                                  final BinaryDistributionLockManager binaryDistributionLockManager); @Transactional(readOnly = true) @Override Application getApplication(Identifier<Application> aApplicationId); @Transactional(readOnly = true) @Override Application getApplication(final String name); @Transactional(readOnly = true) @Override List<Application> getApplications(); @Transactional(readOnly = true) @Override List<Application> findApplications(Identifier<Group> groupId); @Transactional(readOnly = true) @Override List<Application> findApplicationsByJvmId(Identifier<Jvm> jvmId); @Transactional @Override Application updateApplication(UpdateApplicationRequest updateApplicationRequest, User anUpdatingUser); @Transactional @Override Application createApplication(final CreateApplicationRequest createApplicationRequest,
                                         final User aCreatingUser); @Transactional @Override void removeApplication(Identifier<Application> anAppIdToRemove, User user); @Override @Transactional(readOnly = true) List<String> getResourceTemplateNames(final String appName, final String jvmName); @Override @Transactional String updateResourceTemplate(final String appName, final String resourceTemplateName, final String template, final String jvmName, final String groupName); @Override @Transactional // TODO: Have an option to do a hot deploy or not. CommandOutput deployConf(final String appName, final String groupName, final String jvmName,
                                    final String resourceTemplateName, ResourceGroup resourceGroup, User user); @Override @Transactional JpaApplicationConfigTemplate uploadAppTemplate(UploadAppTemplateRequest uploadAppTemplateRequest); @Override @Transactional String previewResourceTemplate(String fileName, String appName, String groupName, String jvmName, String template, ResourceGroup resourceGroup); @Override @Transactional void copyApplicationWarToGroupHosts(Application application); @Override void deployApplicationResourcesToGroupHosts(String groupName, Application app, ResourceGroup resourceGroup); @Override @Transactional void copyApplicationWarToHost(Application application, String hostName); @Override void deployConf(final String appName, final String hostName, final User user);  }