refactored test data generation. Refactored entity factor methods.
Signed-off-by: Kai Zimmermann <kai.zimmermann@bosch-si.com>
This commit is contained in:
@@ -1,15 +0,0 @@
|
||||
<!--
|
||||
|
||||
Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||
|
||||
All rights reserved. This program and the accompanying materials
|
||||
are made available under the terms of the Eclipse Public License v1.0
|
||||
which accompanies this distribution, and is available at
|
||||
http://www.eclipse.org/legal/epl-v10.html
|
||||
|
||||
-->
|
||||
<FindBugsFilter>
|
||||
<Match>
|
||||
<Method name="~_persistence_[sg]et.*" />
|
||||
</Match>
|
||||
</FindBugsFilter>
|
||||
@@ -0,0 +1,33 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.hawkbit;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
||||
/**
|
||||
* Annotation to enable {@link ComponentScan} in the resource package to setup
|
||||
* all {@link Controller} annotated classes and setup the REST-Resources for the
|
||||
* Management API.
|
||||
*/
|
||||
@Target(ElementType.TYPE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Configuration
|
||||
@ComponentScan
|
||||
@Import(RepositoryApplicationConfiguration.class)
|
||||
public @interface EnableJpaRepository {
|
||||
|
||||
}
|
||||
@@ -47,11 +47,10 @@ import org.springframework.validation.beanvalidation.MethodValidationPostProcess
|
||||
@EnableTransactionManagement
|
||||
@EnableJpaAuditing
|
||||
@EnableAspectJAutoProxy
|
||||
@Configuration
|
||||
@ComponentScan
|
||||
@Configuration
|
||||
@EnableAutoConfiguration
|
||||
public class RepositoryApplicationConfiguration extends JpaBaseConfiguration {
|
||||
|
||||
/**
|
||||
* @return the {@link SystemSecurityContext} singleton bean which make it
|
||||
* accessible in beans which cannot access the service directly,
|
||||
|
||||
@@ -288,4 +288,14 @@ public class JpaArtifactManagement implements ArtifactManagement {
|
||||
final boolean overrideExisting, final String contentType) {
|
||||
return createLocalArtifact(inputStream, moduleId, filename, null, null, overrideExisting, contentType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long countLocalArtifactsAll() {
|
||||
return localArtifactRepository.count();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long countExternalArtifactsAll() {
|
||||
return externalArtifactRepository.count();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ package org.eclipse.hawkbit.repository.jpa;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -55,7 +54,6 @@ import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.data.jpa.repository.Modifying;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Isolation;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
@@ -438,33 +436,4 @@ public class JpaControllerManagement implements ControllerManagement {
|
||||
return updateTargetStatus(target, null, System.currentTimeMillis(), address);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(propagation = Propagation.SUPPORTS)
|
||||
public ActionStatus generateActionStatus() {
|
||||
return new JpaActionStatus();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(propagation = Propagation.SUPPORTS)
|
||||
public ActionStatus generateActionStatus(final Action action, final Status status, final Long occurredAt,
|
||||
final String message) {
|
||||
return new JpaActionStatus((JpaAction) action, status, occurredAt, message);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(propagation = Propagation.SUPPORTS)
|
||||
public ActionStatus generateActionStatus(final Action action, final Status status, final Long occurredAt,
|
||||
final Collection<String> messages) {
|
||||
|
||||
final ActionStatus result = new JpaActionStatus((JpaAction) action, status, occurredAt, null);
|
||||
messages.forEach(result::addMessage);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(propagation = Propagation.SUPPORTS)
|
||||
public ActionStatus generateActionStatus(final Action action, final Status status, final Long occurredAt) {
|
||||
return new JpaActionStatus(action, status, occurredAt);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,7 +84,6 @@ import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.data.jpa.repository.Modifying;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Isolation;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
@@ -155,7 +154,8 @@ public class JpaDeploymentManagement implements DeploymentManagement {
|
||||
@Transactional(isolation = Isolation.READ_COMMITTED)
|
||||
@CacheEvict(value = { "distributionUsageAssigned" }, allEntries = true)
|
||||
public DistributionSetAssignmentResult assignDistributionSet(final Long dsID, final String... targetIDs) {
|
||||
return assignDistributionSet(dsID, ActionType.FORCED, org.eclipse.hawkbit.repository.model.Constants.NO_FORCE_TIME, targetIDs);
|
||||
return assignDistributionSet(dsID, ActionType.FORCED,
|
||||
org.eclipse.hawkbit.repository.model.Constants.NO_FORCE_TIME, targetIDs);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -683,12 +683,6 @@ public class JpaDeploymentManagement implements DeploymentManagement {
|
||||
return actionRepository.findByRolloutAndStatus((JpaRollout) rollout, actionStatus);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(propagation = Propagation.SUPPORTS)
|
||||
public Action generateAction() {
|
||||
return new JpaAction();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<ActionStatus> findActionStatusAll(final Pageable pageable) {
|
||||
return convertAcSPage(actionStatusRepository.findAll(pageable), pageable);
|
||||
@@ -697,4 +691,19 @@ public class JpaDeploymentManagement implements DeploymentManagement {
|
||||
private static Page<ActionStatus> convertAcSPage(final Page<JpaActionStatus> findAll, final Pageable pageable) {
|
||||
return new PageImpl<>(new ArrayList<>(findAll.getContent()), pageable, findAll.getTotalElements());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long countActionStatusAll() {
|
||||
return actionStatusRepository.count();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long countActionsAll() {
|
||||
return actionRepository.count();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Slice<Action> findActionsByDistributionSet(final Pageable pageable, final DistributionSet ds) {
|
||||
return actionRepository.findByDistributionSet(pageable, (JpaDistributionSet) ds);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,7 +62,6 @@ import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.data.jpa.repository.Modifying;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Isolation;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
@@ -739,45 +738,6 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
|
||||
return toggleTagAssignment(sets.stream().map(ds -> ds.getId()).collect(Collectors.toList()), tag.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(propagation = Propagation.SUPPORTS)
|
||||
public DistributionSetType generateDistributionSetType() {
|
||||
return new JpaDistributionSetType();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(propagation = Propagation.SUPPORTS)
|
||||
public DistributionSet generateDistributionSet() {
|
||||
return new JpaDistributionSet();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(propagation = Propagation.SUPPORTS)
|
||||
public DistributionSetMetadata generateDistributionSetMetadata() {
|
||||
return new JpaDistributionSetMetadata();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(propagation = Propagation.SUPPORTS)
|
||||
public DistributionSetMetadata generateDistributionSetMetadata(final DistributionSet distributionSet,
|
||||
final String key, final String value) {
|
||||
return new JpaDistributionSetMetadata(key, distributionSet, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(propagation = Propagation.SUPPORTS)
|
||||
public DistributionSetType generateDistributionSetType(final String key, final String name,
|
||||
final String description) {
|
||||
return new JpaDistributionSetType(key, name, description);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(propagation = Propagation.SUPPORTS)
|
||||
public DistributionSet generateDistributionSet(final String name, final String version, final String description,
|
||||
final DistributionSetType type, final Collection<SoftwareModule> moduleList) {
|
||||
return new JpaDistributionSet(name, version, description, type, moduleList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long countDistributionSetsByType(final DistributionSetType type) {
|
||||
return distributionSetRepository.countByType((JpaDistributionSetType) type);
|
||||
|
||||
@@ -0,0 +1,201 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.eclipse.hawkbit.repository.EntityFactory;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaAction;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetMetadata;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetTag;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetType;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaRollout;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleMetadata;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleType;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetFilterQuery;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag;
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.Action.Status;
|
||||
import org.eclipse.hawkbit.repository.model.ActionStatus;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetMetadata;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetTag;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetType;
|
||||
import org.eclipse.hawkbit.repository.model.Rollout;
|
||||
import org.eclipse.hawkbit.repository.model.RolloutGroup;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModuleMetadata;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.model.TargetFilterQuery;
|
||||
import org.eclipse.hawkbit.repository.model.TargetTag;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* JPA Implementation of {@link EntityFactory}.
|
||||
*
|
||||
*/
|
||||
@Service
|
||||
public class JpaEntityFactory implements EntityFactory {
|
||||
|
||||
@Override
|
||||
public DistributionSetType generateDistributionSetType() {
|
||||
return new JpaDistributionSetType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DistributionSet generateDistributionSet() {
|
||||
return new JpaDistributionSet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DistributionSetMetadata generateDistributionSetMetadata() {
|
||||
return new JpaDistributionSetMetadata();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DistributionSetMetadata generateDistributionSetMetadata(final DistributionSet distributionSet,
|
||||
final String key, final String value) {
|
||||
return new JpaDistributionSetMetadata(key, distributionSet, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DistributionSetType generateDistributionSetType(final String key, final String name,
|
||||
final String description) {
|
||||
return new JpaDistributionSetType(key, name, description);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DistributionSet generateDistributionSet(final String name, final String version, final String description,
|
||||
final DistributionSetType type, final Collection<SoftwareModule> moduleList) {
|
||||
return new JpaDistributionSet(name, version, description, type, moduleList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Target generateTarget(final String controllerId) {
|
||||
return new JpaTarget(controllerId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TargetTag generateTargetTag() {
|
||||
return new JpaTargetTag();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DistributionSetTag generateDistributionSetTag() {
|
||||
return new JpaDistributionSetTag();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TargetTag generateTargetTag(final String name, final String description, final String colour) {
|
||||
return new JpaTargetTag(name, description, colour);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DistributionSetTag generateDistributionSetTag(final String name, final String description,
|
||||
final String colour) {
|
||||
return new JpaDistributionSetTag(name, description, colour);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TargetTag generateTargetTag(final String name) {
|
||||
return new JpaTargetTag(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DistributionSetTag generateDistributionSetTag(final String name) {
|
||||
return new JpaDistributionSetTag(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TargetFilterQuery generateTargetFilterQuery() {
|
||||
return new JpaTargetFilterQuery();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SoftwareModuleType generateSoftwareModuleType() {
|
||||
return new JpaSoftwareModuleType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SoftwareModule generateSoftwareModule() {
|
||||
return new JpaSoftwareModule();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SoftwareModule generateSoftwareModule(final SoftwareModuleType type, final String name, final String version,
|
||||
final String description, final String vendor) {
|
||||
|
||||
return new JpaSoftwareModule(type, name, version, description, vendor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SoftwareModuleMetadata generateSoftwareModuleMetadata() {
|
||||
return new JpaSoftwareModuleMetadata();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SoftwareModuleMetadata generateSoftwareModuleMetadata(final SoftwareModule softwareModule, final String key,
|
||||
final String value) {
|
||||
return new JpaSoftwareModuleMetadata(key, softwareModule, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SoftwareModuleType generateSoftwareModuleType(final String key, final String name, final String description,
|
||||
final int maxAssignments) {
|
||||
return new JpaSoftwareModuleType(key, name, description, maxAssignments);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Rollout generateRollout() {
|
||||
return new JpaRollout();
|
||||
}
|
||||
|
||||
@Override
|
||||
public RolloutGroup generateRolloutGroup() {
|
||||
return new JpaRolloutGroup();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Action generateAction() {
|
||||
return new JpaAction();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionStatus generateActionStatus() {
|
||||
return new JpaActionStatus();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionStatus generateActionStatus(final Action action, final Status status, final Long occurredAt,
|
||||
final String message) {
|
||||
return new JpaActionStatus((JpaAction) action, status, occurredAt, message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionStatus generateActionStatus(final Action action, final Status status, final Long occurredAt,
|
||||
final Collection<String> messages) {
|
||||
|
||||
final ActionStatus result = new JpaActionStatus((JpaAction) action, status, occurredAt, null);
|
||||
messages.forEach(result::addMessage);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionStatus generateActionStatus(final Action action, final Status status, final Long occurredAt) {
|
||||
return new JpaActionStatus(action, status, occurredAt);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -49,7 +49,6 @@ import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Isolation;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
@@ -201,9 +200,4 @@ public class JpaRolloutGroupManagement implements RolloutGroupManagement {
|
||||
return new PageImpl<>(targetWithActionStatus, pageRequest, totalCount);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(propagation = Propagation.SUPPORTS)
|
||||
public RolloutGroup generateRolloutGroup() {
|
||||
return new JpaRolloutGroup();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -667,9 +667,4 @@ public class JpaRolloutManagement implements RolloutManagement {
|
||||
return ((float) finished / (float) totalGroup) * 100;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(propagation = Propagation.SUPPORTS)
|
||||
public Rollout generateRollout() {
|
||||
return new JpaRollout();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,7 +62,6 @@ import org.springframework.data.jpa.repository.Modifying;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Isolation;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
@@ -663,44 +662,4 @@ public class JpaSoftwareManagement implements SoftwareManagement {
|
||||
return types.stream().map(this::createSoftwareModuleType).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(propagation = Propagation.SUPPORTS)
|
||||
public SoftwareModuleType generateSoftwareModuleType() {
|
||||
return new JpaSoftwareModuleType();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(propagation = Propagation.SUPPORTS)
|
||||
public SoftwareModule generateSoftwareModule() {
|
||||
return new JpaSoftwareModule();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(propagation = Propagation.SUPPORTS)
|
||||
public SoftwareModule generateSoftwareModule(final SoftwareModuleType type, final String name, final String version,
|
||||
final String description, final String vendor) {
|
||||
|
||||
return new JpaSoftwareModule(type, name, version, description, vendor);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(propagation = Propagation.SUPPORTS)
|
||||
public SoftwareModuleMetadata generateSoftwareModuleMetadata() {
|
||||
return new JpaSoftwareModuleMetadata();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(propagation = Propagation.SUPPORTS)
|
||||
public SoftwareModuleMetadata generateSoftwareModuleMetadata(final SoftwareModule softwareModule, final String key,
|
||||
final String value) {
|
||||
return new JpaSoftwareModuleMetadata(key, softwareModule, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(propagation = Propagation.SUPPORTS)
|
||||
public SoftwareModuleType generateSoftwareModuleType(final String key, final String name, final String description,
|
||||
final int maxAssignments) {
|
||||
return new JpaSoftwareModuleType(key, name, description, maxAssignments);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -259,28 +259,6 @@ public class JpaSystemManagement implements SystemManagement {
|
||||
return tenantMetaDataRepository.save((JpaTenantMetaData) metaData);
|
||||
}
|
||||
|
||||
private DistributionSetType createStandardSoftwareDataSetup() {
|
||||
final SoftwareModuleType eclApp = softwareModuleTypeRepository.save(new JpaSoftwareModuleType("application",
|
||||
"ECL Application", "Edge Controller Linux base application type", 1));
|
||||
final SoftwareModuleType eclOs = softwareModuleTypeRepository.save(
|
||||
new JpaSoftwareModuleType("os", "ECL OS", "Edge Controller Linux operation system image type", 1));
|
||||
final SoftwareModuleType eclJvm = softwareModuleTypeRepository.save(
|
||||
new JpaSoftwareModuleType("runtime", "ECL JVM", "Edge Controller Linux java virtual machine type.", 1));
|
||||
|
||||
distributionSetTypeRepository.save((JpaDistributionSetType) new JpaDistributionSetType("ecl_os", "OS only",
|
||||
"Standard Edge Controller Linux distribution set type.").addMandatoryModuleType(eclOs));
|
||||
|
||||
distributionSetTypeRepository.save((JpaDistributionSetType) new JpaDistributionSetType("ecl_os_app",
|
||||
"OS with optional app", "Standard Edge Controller Linux distribution set type. OS only.")
|
||||
.addMandatoryModuleType(eclOs).addOptionalModuleType(eclApp));
|
||||
|
||||
return distributionSetTypeRepository.save(
|
||||
(JpaDistributionSetType) new JpaDistributionSetType("ecl_os_app_jvm", "OS with optional app and jvm",
|
||||
"Standard Edge Controller Linux distribution set type. OS with optional application.")
|
||||
.addMandatoryModuleType(eclOs).addOptionalModuleType(eclApp)
|
||||
.addOptionalModuleType(eclJvm));
|
||||
}
|
||||
|
||||
/**
|
||||
* A implementation of the {@link KeyGenerator} to generate a key based on
|
||||
* either the {@code createInitialTenant} thread local and the
|
||||
@@ -303,4 +281,18 @@ public class JpaSystemManagement implements SystemManagement {
|
||||
initialTenantCreation.toUpperCase());
|
||||
}
|
||||
}
|
||||
|
||||
private DistributionSetType createStandardSoftwareDataSetup() {
|
||||
final SoftwareModuleType app = softwareModuleTypeRepository
|
||||
.save(new JpaSoftwareModuleType("application", "Application", "Application Addons", Integer.MAX_VALUE));
|
||||
final SoftwareModuleType os = softwareModuleTypeRepository
|
||||
.save(new JpaSoftwareModuleType("os", "Firmware", "Core firmware or operationg system", 1));
|
||||
|
||||
distributionSetTypeRepository.save((JpaDistributionSetType) new JpaDistributionSetType("os_app", "With app(s)",
|
||||
"Default type with Firmware/OS and optional app(s).").addMandatoryModuleType(os)
|
||||
.addOptionalModuleType(app));
|
||||
|
||||
return distributionSetTypeRepository.save((JpaDistributionSetType) new JpaDistributionSetType("os", "OS only",
|
||||
"Default type with Firmware/OS only.").addMandatoryModuleType(os));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,6 @@ import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.data.jpa.repository.Modifying;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Isolation;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
@@ -287,41 +286,4 @@ public class JpaTagManagement implements TagManagement {
|
||||
return convertDsPage(distributionSetTagRepository.findAll(spec, pageable), pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(propagation = Propagation.SUPPORTS)
|
||||
public TargetTag generateTargetTag() {
|
||||
return new JpaTargetTag();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(propagation = Propagation.SUPPORTS)
|
||||
public DistributionSetTag generateDistributionSetTag() {
|
||||
return new JpaDistributionSetTag();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(propagation = Propagation.SUPPORTS)
|
||||
public TargetTag generateTargetTag(final String name, final String description, final String colour) {
|
||||
return new JpaTargetTag(name, description, colour);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(propagation = Propagation.SUPPORTS)
|
||||
public DistributionSetTag generateDistributionSetTag(final String name, final String description,
|
||||
final String colour) {
|
||||
return new JpaDistributionSetTag(name, description, colour);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(propagation = Propagation.SUPPORTS)
|
||||
public TargetTag generateTargetTag(final String name) {
|
||||
return new JpaTargetTag(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(propagation = Propagation.SUPPORTS)
|
||||
public DistributionSetTag generateDistributionSetTag(final String name) {
|
||||
return new JpaDistributionSetTag(name);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -109,9 +109,4 @@ public class JpaTargetFilterQueryManagement implements TargetFilterQueryManageme
|
||||
return targetFilterQueryRepository.save((JpaTargetFilterQuery) targetFilterQuery);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TargetFilterQuery generateTargetFilterQuery() {
|
||||
return new JpaTargetFilterQuery();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -61,7 +61,6 @@ import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.data.jpa.repository.Modifying;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Isolation;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
@@ -403,7 +402,6 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
@Modifying
|
||||
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
|
||||
public Target unAssignTag(final String controllerID, final TargetTag targetTag) {
|
||||
// TODO : optimize this, findone?
|
||||
final List<Target> allTargets = new ArrayList<>(targetRepository
|
||||
.findAll(TargetSpecifications.byControllerIdWithStatusAndTagsInJoin(Arrays.asList(controllerID))));
|
||||
final List<Target> unAssignTag = unAssignTag(allTargets, targetTag);
|
||||
@@ -673,9 +671,4 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
return resultList;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(propagation = Propagation.SUPPORTS)
|
||||
public Target generateTarget(final String controllerId) {
|
||||
return new JpaTarget(controllerId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,16 +53,11 @@ public class CacheFieldEntityListener {
|
||||
@SuppressWarnings("rawtypes")
|
||||
final String id = ((Identifiable) target).getId().toString();
|
||||
final Class<? extends Object> type = target.getClass();
|
||||
findCacheFields(type, id, new CacheFieldCallback() {
|
||||
@Override
|
||||
public void fromCache(final Field field, final String cacheKey, final Serializable id)
|
||||
throws IllegalAccessException {
|
||||
final Cache cache = cacheManager.getCache(type.getName());
|
||||
final ValueWrapper valueWrapper = cache
|
||||
.get(CacheKeys.entitySpecificCacheKey(id.toString(), cacheKey));
|
||||
if (valueWrapper != null && valueWrapper.get() != null) {
|
||||
FieldUtils.writeField(field, target, valueWrapper.get(), true);
|
||||
}
|
||||
findCacheFields(type, id, (field, cacheKey, id1) -> {
|
||||
final Cache cache = cacheManager.getCache(type.getName());
|
||||
final ValueWrapper valueWrapper = cache.get(CacheKeys.entitySpecificCacheKey(id1.toString(), cacheKey));
|
||||
if (valueWrapper != null && valueWrapper.get() != null) {
|
||||
FieldUtils.writeField(field, target, valueWrapper.get(), true);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -82,13 +77,9 @@ public class CacheFieldEntityListener {
|
||||
@SuppressWarnings("rawtypes")
|
||||
final String id = ((Identifiable) target).getId().toString();
|
||||
final Class<? extends Object> type = target.getClass();
|
||||
findCacheFields(type, id, new CacheFieldCallback() {
|
||||
@Override
|
||||
public void fromCache(final Field field, final String cacheKey, final Serializable id)
|
||||
throws IllegalAccessException {
|
||||
final Cache cache = cacheManager.getCache(type.getName());
|
||||
cache.evict(CacheKeys.entitySpecificCacheKey(id.toString(), cacheKey));
|
||||
}
|
||||
findCacheFields(type, id, (field, cacheKey, id1) -> {
|
||||
final Cache cache = cacheManager.getCache(type.getName());
|
||||
cache.evict(CacheKeys.entitySpecificCacheKey(id1.toString(), cacheKey));
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -109,6 +100,7 @@ public class CacheFieldEntityListener {
|
||||
}
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
private interface CacheFieldCallback {
|
||||
/**
|
||||
* callback methods which is called by the
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa.model.helper;
|
||||
|
||||
import org.eclipse.hawkbit.repository.SystemManagement;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
/**
|
||||
* A singleton bean which holds {@link SystemManagement} service and makes it
|
||||
* accessible to beans which are not managed by spring, e.g. JPA entities.
|
||||
*
|
||||
*
|
||||
*
|
||||
**/
|
||||
public final class SystemManagementHolder {
|
||||
|
||||
private static final SystemManagementHolder INSTANCE = new SystemManagementHolder();
|
||||
|
||||
@Autowired
|
||||
private SystemManagement systemManagement;
|
||||
|
||||
private SystemManagementHolder() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the singleton {@link SystemManagementHolder} instance
|
||||
*/
|
||||
public static SystemManagementHolder getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the systemManagement
|
||||
*/
|
||||
public SystemManagement getSystemManagement() {
|
||||
return systemManagement;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param systemManagement
|
||||
* the systemManagement to set
|
||||
*/
|
||||
public void setSystemManagement(final SystemManagement systemManagement) {
|
||||
this.systemManagement = systemManagement;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the {@link SystemManagement#currentTenant()}.
|
||||
*/
|
||||
public String currentTenant() {
|
||||
return systemManagement.currentTenant();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -12,8 +12,9 @@ import org.eclipse.hawkbit.repository.model.Rollout;
|
||||
import org.eclipse.hawkbit.repository.model.RolloutGroup;
|
||||
|
||||
/**
|
||||
*
|
||||
* Verifies {@link RolloutGroup#getErrorConditionExp()}.
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface RolloutGroupConditionEvaluator {
|
||||
|
||||
default boolean verifyExpression(final String expression) {
|
||||
|
||||
@@ -1,333 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
|
||||
import org.eclipse.hawkbit.ExcludePathAwareShallowETagFilter;
|
||||
import org.eclipse.hawkbit.RepositoryApplicationConfiguration;
|
||||
import org.eclipse.hawkbit.cache.TenantAwareCacheManager;
|
||||
import org.eclipse.hawkbit.repository.ArtifactManagement;
|
||||
import org.eclipse.hawkbit.repository.ControllerManagement;
|
||||
import org.eclipse.hawkbit.repository.DeploymentManagement;
|
||||
import org.eclipse.hawkbit.repository.DistributionSetManagement;
|
||||
import org.eclipse.hawkbit.repository.RolloutGroupManagement;
|
||||
import org.eclipse.hawkbit.repository.RolloutManagement;
|
||||
import org.eclipse.hawkbit.repository.SoftwareManagement;
|
||||
import org.eclipse.hawkbit.repository.SystemManagement;
|
||||
import org.eclipse.hawkbit.repository.TagManagement;
|
||||
import org.eclipse.hawkbit.repository.TargetFilterQueryManagement;
|
||||
import org.eclipse.hawkbit.repository.TargetManagement;
|
||||
import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
|
||||
import org.eclipse.hawkbit.repository.jpa.ActionRepository;
|
||||
import org.eclipse.hawkbit.repository.jpa.ActionStatusRepository;
|
||||
import org.eclipse.hawkbit.repository.jpa.DistributionSetRepository;
|
||||
import org.eclipse.hawkbit.repository.jpa.DistributionSetTagRepository;
|
||||
import org.eclipse.hawkbit.repository.jpa.DistributionSetTypeRepository;
|
||||
import org.eclipse.hawkbit.repository.jpa.ExternalArtifactRepository;
|
||||
import org.eclipse.hawkbit.repository.jpa.LocalArtifactRepository;
|
||||
import org.eclipse.hawkbit.repository.jpa.RolloutGroupRepository;
|
||||
import org.eclipse.hawkbit.repository.jpa.RolloutRepository;
|
||||
import org.eclipse.hawkbit.repository.jpa.SoftwareModuleMetadataRepository;
|
||||
import org.eclipse.hawkbit.repository.jpa.SoftwareModuleRepository;
|
||||
import org.eclipse.hawkbit.repository.jpa.SoftwareModuleTypeRepository;
|
||||
import org.eclipse.hawkbit.repository.jpa.TargetInfoRepository;
|
||||
import org.eclipse.hawkbit.repository.jpa.TargetRepository;
|
||||
import org.eclipse.hawkbit.repository.jpa.TargetTagRepository;
|
||||
import org.eclipse.hawkbit.repository.jpa.TenantMetaDataRepository;
|
||||
import org.eclipse.hawkbit.repository.jpa.utils.RepositoryDataGenerator.DatabaseCleanupUtil;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetType;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
|
||||
import org.eclipse.hawkbit.security.DosFilter;
|
||||
import org.eclipse.hawkbit.security.SystemSecurityContext;
|
||||
import org.eclipse.hawkbit.tenancy.TenantAware;
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Rule;
|
||||
import org.junit.rules.MethodRule;
|
||||
import org.junit.rules.TestWatchman;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.model.FrameworkMethod;
|
||||
import org.slf4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.context.EnvironmentAware;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.data.auditing.AuditingHandler;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.mongodb.gridfs.GridFsOperations;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.annotation.DirtiesContext.ClassMode;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.web.WebAppConfiguration;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.setup.DefaultMockMvcBuilder;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@WebAppConfiguration
|
||||
@SpringApplicationConfiguration(classes = { RepositoryApplicationConfiguration.class, TestConfiguration.class })
|
||||
@ActiveProfiles({ "test" })
|
||||
@WithUser(principal = "bumlux", allSpPermissions = true, authorities = "ROLE_CONTROLLER")
|
||||
// destroy the context after each test class because otherwise we get problem
|
||||
// when context is
|
||||
// refreshed we e.g. get two instances of CacheManager which leads to very
|
||||
// strange test failures.
|
||||
@DirtiesContext(classMode = ClassMode.AFTER_CLASS)
|
||||
public abstract class AbstractIntegrationTest implements EnvironmentAware {
|
||||
protected static Logger LOG = null;
|
||||
|
||||
protected static final Pageable pageReq = new PageRequest(0, 400);
|
||||
|
||||
@PersistenceContext
|
||||
protected EntityManager entityManager;
|
||||
|
||||
@Autowired
|
||||
protected TargetRepository targetRepository;
|
||||
|
||||
@Autowired
|
||||
protected ActionRepository actionRepository;
|
||||
|
||||
@Autowired
|
||||
protected DistributionSetRepository distributionSetRepository;
|
||||
|
||||
@Autowired
|
||||
protected SoftwareModuleRepository softwareModuleRepository;
|
||||
|
||||
@Autowired
|
||||
protected TenantMetaDataRepository tenantMetaDataRepository;
|
||||
|
||||
@Autowired
|
||||
protected DistributionSetTypeRepository distributionSetTypeRepository;
|
||||
|
||||
@Autowired
|
||||
protected SoftwareModuleTypeRepository softwareModuleTypeRepository;
|
||||
|
||||
@Autowired
|
||||
protected TargetTagRepository targetTagRepository;
|
||||
|
||||
@Autowired
|
||||
protected DistributionSetTagRepository distributionSetTagRepository;
|
||||
|
||||
@Autowired
|
||||
protected SoftwareModuleMetadataRepository softwareModuleMetadataRepository;
|
||||
|
||||
@Autowired
|
||||
protected ActionStatusRepository actionStatusRepository;
|
||||
|
||||
@Autowired
|
||||
protected ExternalArtifactRepository externalArtifactRepository;
|
||||
|
||||
@Autowired
|
||||
protected SoftwareManagement softwareManagement;
|
||||
|
||||
@Autowired
|
||||
protected DistributionSetManagement distributionSetManagement;
|
||||
|
||||
@Autowired
|
||||
protected ControllerManagement controllerManagement;
|
||||
|
||||
@Autowired
|
||||
protected TargetManagement targetManagement;
|
||||
|
||||
@Autowired
|
||||
protected TargetFilterQueryManagement targetFilterQueryManagement;
|
||||
|
||||
@Autowired
|
||||
protected TagManagement tagManagement;
|
||||
|
||||
@Autowired
|
||||
protected DeploymentManagement deploymentManagement;
|
||||
|
||||
@Autowired
|
||||
protected ArtifactManagement artifactManagement;
|
||||
|
||||
@Autowired
|
||||
protected LocalArtifactRepository artifactRepository;
|
||||
|
||||
@Autowired
|
||||
protected TargetInfoRepository targetInfoRepository;
|
||||
|
||||
@Autowired
|
||||
protected GridFsOperations operations;
|
||||
|
||||
@Autowired
|
||||
protected WebApplicationContext context;
|
||||
|
||||
@Autowired
|
||||
protected ControllerManagement controllerManagament;
|
||||
|
||||
@Autowired
|
||||
protected AuditingHandler auditingHandler;
|
||||
|
||||
@Autowired
|
||||
protected TenantAware tenantAware;
|
||||
|
||||
@Autowired
|
||||
protected SystemManagement systemManagement;
|
||||
|
||||
@Autowired
|
||||
protected TenantAwareCacheManager cacheManager;
|
||||
|
||||
@Autowired
|
||||
protected TenantConfigurationManagement tenantConfigurationManagement;
|
||||
|
||||
@Autowired
|
||||
protected RolloutManagement rolloutManagement;
|
||||
|
||||
@Autowired
|
||||
protected RolloutGroupManagement rolloutGroupManagement;
|
||||
|
||||
@Autowired
|
||||
protected RolloutGroupRepository rolloutGroupRepository;
|
||||
|
||||
@Autowired
|
||||
protected RolloutRepository rolloutRepository;
|
||||
|
||||
@Autowired
|
||||
protected SystemSecurityContext systemSecurityContext;
|
||||
|
||||
protected MockMvc mvc;
|
||||
|
||||
@Autowired
|
||||
protected DatabaseCleanupUtil dbCleanupUtil;
|
||||
|
||||
protected SoftwareModuleType osType;
|
||||
protected SoftwareModuleType appType;
|
||||
protected SoftwareModuleType runtimeType;
|
||||
|
||||
protected DistributionSetType standardDsType;
|
||||
|
||||
@Rule
|
||||
public final WithSpringAuthorityRule securityRule = new WithSpringAuthorityRule();
|
||||
|
||||
protected Environment environment = null;
|
||||
|
||||
private static CIMySqlTestDatabase tesdatabase;
|
||||
|
||||
@Override
|
||||
public void setEnvironment(final Environment environment) {
|
||||
this.environment = environment;
|
||||
}
|
||||
|
||||
@Before
|
||||
public void before() throws Exception {
|
||||
mvc = createMvcWebAppContext().build();
|
||||
|
||||
standardDsType = securityRule.runAsPrivileged(() -> systemManagement.getTenantMetadata().getDefaultDsType());
|
||||
|
||||
osType = securityRule.runAsPrivileged(() -> softwareManagement.findSoftwareModuleTypeByKey("os"));
|
||||
osType.setDescription("Updated description to have lastmodified available in tests");
|
||||
osType = securityRule.runAsPrivileged(() -> softwareManagement.updateSoftwareModuleType(osType));
|
||||
|
||||
appType = securityRule.runAsPrivileged(() -> softwareManagement.findSoftwareModuleTypeByKey("application"));
|
||||
appType.setDescription("Updated description to have lastmodified available in tests");
|
||||
appType = securityRule.runAsPrivileged(() -> softwareManagement.updateSoftwareModuleType(appType));
|
||||
|
||||
runtimeType = securityRule.runAsPrivileged(() -> softwareManagement.findSoftwareModuleTypeByKey("runtime"));
|
||||
runtimeType.setDescription("Updated description to have lastmodified available in tests");
|
||||
runtimeType = securityRule.runAsPrivileged(() -> softwareManagement.updateSoftwareModuleType(runtimeType));
|
||||
}
|
||||
|
||||
protected DefaultMockMvcBuilder createMvcWebAppContext() {
|
||||
return MockMvcBuilders.webAppContextSetup(context)
|
||||
.addFilter(new DosFilter(100, 10, "127\\.0\\.0\\.1|\\[0:0:0:0:0:0:0:1\\]", "(^192\\.168\\.)",
|
||||
"X-Forwarded-For"))
|
||||
.addFilter(new ExcludePathAwareShallowETagFilter(
|
||||
"/rest/v1/softwaremodules/{smId}/artifacts/{artId}/download", "/*/controller/artifacts/**"));
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass() {
|
||||
createTestdatabaseAndStart();
|
||||
}
|
||||
|
||||
private static void createTestdatabaseAndStart() {
|
||||
if ("MYSQL".equals(System.getProperty("spring.jpa.database"))) {
|
||||
tesdatabase = new CIMySqlTestDatabase();
|
||||
tesdatabase.before();
|
||||
}
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterClass() {
|
||||
if (tesdatabase != null) {
|
||||
tesdatabase.after();
|
||||
}
|
||||
}
|
||||
|
||||
@After
|
||||
public void after() throws Exception {
|
||||
deleteAllRepos();
|
||||
cacheManager.getDirectCacheNames().forEach(name -> cacheManager.getDirectCache(name).clear());
|
||||
assertThat(actionStatusRepository.findAll()).isEmpty();
|
||||
assertThat(targetRepository.findAll()).isEmpty();
|
||||
assertThat(actionRepository.findAll()).isEmpty();
|
||||
assertThat(distributionSetRepository.findAll()).isEmpty();
|
||||
assertThat(targetTagRepository.findAll()).isEmpty();
|
||||
assertThat(distributionSetTagRepository.findAll()).isEmpty();
|
||||
assertThat(softwareModuleRepository.findAll()).isEmpty();
|
||||
assertThat(softwareModuleTypeRepository.findAll()).isEmpty();
|
||||
assertThat(distributionSetTypeRepository.findAll()).isEmpty();
|
||||
assertThat(tenantMetaDataRepository.findAll()).isEmpty();
|
||||
assertThat(rolloutGroupRepository.findAll()).isEmpty();
|
||||
assertThat(rolloutRepository.findAll()).isEmpty();
|
||||
}
|
||||
|
||||
@Transactional
|
||||
protected void deleteAllRepos() throws Exception {
|
||||
final List<String> tenants = securityRule.runAs(WithSpringAuthorityRule.withUser(false),
|
||||
() -> systemManagement.findTenants());
|
||||
tenants.forEach(tenant -> {
|
||||
try {
|
||||
securityRule.runAs(WithSpringAuthorityRule.withUser(false), () -> {
|
||||
systemManagement.deleteTenant(tenant);
|
||||
return null;
|
||||
});
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Rule
|
||||
public MethodRule watchman = new TestWatchman() {
|
||||
@Override
|
||||
public void starting(final FrameworkMethod method) {
|
||||
if (LOG != null) {
|
||||
LOG.info("Starting Test {}...", method.getName());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void succeeded(final FrameworkMethod method) {
|
||||
if (LOG != null) {
|
||||
LOG.info("Test {} succeeded.", method.getName());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void failed(final Throwable e, final FrameworkMethod method) {
|
||||
if (LOG != null) {
|
||||
LOG.error("Test {} failed with {}.", method.getName(), e);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -1,104 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.springframework.data.mongodb.core.query.Query;
|
||||
|
||||
import de.flapdoodle.embed.mongo.Command;
|
||||
import de.flapdoodle.embed.mongo.MongodExecutable;
|
||||
import de.flapdoodle.embed.mongo.MongodStarter;
|
||||
import de.flapdoodle.embed.mongo.config.ArtifactStoreBuilder;
|
||||
import de.flapdoodle.embed.mongo.config.DownloadConfigBuilder;
|
||||
import de.flapdoodle.embed.mongo.config.IMongodConfig;
|
||||
import de.flapdoodle.embed.mongo.config.MongodConfigBuilder;
|
||||
import de.flapdoodle.embed.mongo.config.Net;
|
||||
import de.flapdoodle.embed.mongo.config.RuntimeConfigBuilder;
|
||||
import de.flapdoodle.embed.mongo.distribution.Version;
|
||||
import de.flapdoodle.embed.process.config.store.HttpProxyFactory;
|
||||
import de.flapdoodle.embed.process.runtime.Network;
|
||||
|
||||
/**
|
||||
* Test class that contains MonfoDb start and stop for the test
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
public abstract class AbstractIntegrationTestWithMongoDB extends AbstractIntegrationTest {
|
||||
protected static volatile MongodExecutable mongodExecutable = null;
|
||||
private static final AtomicInteger mongoLease = new AtomicInteger(0);
|
||||
private static volatile Integer port;
|
||||
|
||||
@BeforeClass
|
||||
public static void setupMongo() throws UnknownHostException, IOException {
|
||||
mongoLease.incrementAndGet();
|
||||
if (mongodExecutable == null) {
|
||||
final Command command = Command.MongoD;
|
||||
|
||||
final RuntimeConfigBuilder runtimeConfig = new RuntimeConfigBuilder().defaults(command);
|
||||
|
||||
if (port == null) {
|
||||
port = new FreePortFileWriter(28017, 28090, "./target/freeports").getPort();
|
||||
System.setProperty("spring.data.mongodb.port", String.valueOf(port));
|
||||
}
|
||||
|
||||
Version version = Version.V3_0_8;
|
||||
if (System.getProperty("inf.mongodb.version") != null) {
|
||||
version = Version
|
||||
.valueOf("V" + System.getProperty("inf.mongodb.version").trim().replaceAll("\\.", "_"));
|
||||
}
|
||||
|
||||
if (System.getProperty("http.proxyHost") != null) {
|
||||
runtimeConfig
|
||||
.artifactStore(
|
||||
new ArtifactStoreBuilder().defaults(command)
|
||||
.download(new DownloadConfigBuilder().defaultsForCommand(command)
|
||||
.proxyFactory(new HttpProxyFactory(
|
||||
System.getProperty("http.proxyHost").trim(),
|
||||
Integer.valueOf(System.getProperty("http.proxyPort"))))));
|
||||
}
|
||||
|
||||
final IMongodConfig mongodConfig = new MongodConfigBuilder().version(version)
|
||||
.net(new Net("127.0.0.1", port, Network.localhostIsIPv6())).build();
|
||||
|
||||
final MongodStarter starter = MongodStarter.getInstance(runtimeConfig.build());
|
||||
mongodExecutable = starter.prepare(mongodConfig);
|
||||
mongodExecutable.start();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@After
|
||||
public void cleanCurrentCollection() {
|
||||
operations.delete(new Query());
|
||||
}
|
||||
|
||||
public void internalShutDownMongo() {
|
||||
if (mongodExecutable != null && mongoLease.decrementAndGet() <= 0) {
|
||||
mongodExecutable.stop();
|
||||
mongodExecutable = null;
|
||||
}
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void shutdownMongo() throws UnknownHostException, IOException {
|
||||
if (mongodExecutable != null && mongoLease.decrementAndGet() <= 0) {
|
||||
mongodExecutable.stop();
|
||||
mongodExecutable = null;
|
||||
}
|
||||
port = null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
|
||||
import org.eclipse.hawkbit.cache.TenantAwareCacheManager;
|
||||
import org.eclipse.hawkbit.repository.util.AbstractIntegrationTest;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.data.mongodb.gridfs.GridFsOperations;
|
||||
|
||||
@SpringApplicationConfiguration(classes = { org.eclipse.hawkbit.RepositoryApplicationConfiguration.class,
|
||||
TestConfiguration.class })
|
||||
public abstract class AbstractJpaIntegrationTest extends AbstractIntegrationTest {
|
||||
|
||||
@PersistenceContext
|
||||
protected EntityManager entityManager;
|
||||
|
||||
@Autowired
|
||||
protected TargetRepository targetRepository;
|
||||
|
||||
@Autowired
|
||||
protected ActionRepository actionRepository;
|
||||
|
||||
@Autowired
|
||||
protected DistributionSetRepository distributionSetRepository;
|
||||
|
||||
@Autowired
|
||||
protected SoftwareModuleRepository softwareModuleRepository;
|
||||
|
||||
@Autowired
|
||||
protected TenantMetaDataRepository tenantMetaDataRepository;
|
||||
|
||||
@Autowired
|
||||
protected DistributionSetTypeRepository distributionSetTypeRepository;
|
||||
|
||||
@Autowired
|
||||
protected SoftwareModuleTypeRepository softwareModuleTypeRepository;
|
||||
|
||||
@Autowired
|
||||
protected TargetTagRepository targetTagRepository;
|
||||
|
||||
@Autowired
|
||||
protected DistributionSetTagRepository distributionSetTagRepository;
|
||||
|
||||
@Autowired
|
||||
protected SoftwareModuleMetadataRepository softwareModuleMetadataRepository;
|
||||
|
||||
@Autowired
|
||||
protected ActionStatusRepository actionStatusRepository;
|
||||
|
||||
@Autowired
|
||||
protected ExternalArtifactRepository externalArtifactRepository;
|
||||
|
||||
@Autowired
|
||||
protected LocalArtifactRepository artifactRepository;
|
||||
|
||||
@Autowired
|
||||
protected TargetInfoRepository targetInfoRepository;
|
||||
|
||||
@Autowired
|
||||
protected GridFsOperations operations;
|
||||
|
||||
@Autowired
|
||||
protected RolloutGroupRepository rolloutGroupRepository;
|
||||
|
||||
@Autowired
|
||||
protected RolloutRepository rolloutRepository;
|
||||
|
||||
@Autowired
|
||||
protected TenantAwareCacheManager cacheManager;
|
||||
|
||||
private static CIMySqlTestDatabase tesdatabase;
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass() {
|
||||
createTestdatabaseAndStart();
|
||||
}
|
||||
|
||||
private static void createTestdatabaseAndStart() {
|
||||
if ("MYSQL".equals(System.getProperty("spring.jpa.database"))) {
|
||||
tesdatabase = new CIMySqlTestDatabase();
|
||||
tesdatabase.before();
|
||||
}
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterClass() {
|
||||
if (tesdatabase != null) {
|
||||
tesdatabase.after();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
|
||||
import org.eclipse.hawkbit.cache.TenantAwareCacheManager;
|
||||
import org.eclipse.hawkbit.repository.util.AbstractIntegrationTestWithMongoDB;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.data.mongodb.gridfs.GridFsOperations;
|
||||
|
||||
@SpringApplicationConfiguration(classes = { org.eclipse.hawkbit.RepositoryApplicationConfiguration.class,
|
||||
TestConfiguration.class })
|
||||
public abstract class AbstractJpaIntegrationTestWithMongoDB extends AbstractIntegrationTestWithMongoDB {
|
||||
|
||||
@PersistenceContext
|
||||
protected EntityManager entityManager;
|
||||
|
||||
@Autowired
|
||||
protected TargetRepository targetRepository;
|
||||
|
||||
@Autowired
|
||||
protected ActionRepository actionRepository;
|
||||
|
||||
@Autowired
|
||||
protected DistributionSetRepository distributionSetRepository;
|
||||
|
||||
@Autowired
|
||||
protected SoftwareModuleRepository softwareModuleRepository;
|
||||
|
||||
@Autowired
|
||||
protected TenantMetaDataRepository tenantMetaDataRepository;
|
||||
|
||||
@Autowired
|
||||
protected DistributionSetTypeRepository distributionSetTypeRepository;
|
||||
|
||||
@Autowired
|
||||
protected SoftwareModuleTypeRepository softwareModuleTypeRepository;
|
||||
|
||||
@Autowired
|
||||
protected TargetTagRepository targetTagRepository;
|
||||
|
||||
@Autowired
|
||||
protected DistributionSetTagRepository distributionSetTagRepository;
|
||||
|
||||
@Autowired
|
||||
protected SoftwareModuleMetadataRepository softwareModuleMetadataRepository;
|
||||
|
||||
@Autowired
|
||||
protected ActionStatusRepository actionStatusRepository;
|
||||
|
||||
@Autowired
|
||||
protected ExternalArtifactRepository externalArtifactRepository;
|
||||
|
||||
@Autowired
|
||||
protected LocalArtifactRepository artifactRepository;
|
||||
|
||||
@Autowired
|
||||
protected TargetInfoRepository targetInfoRepository;
|
||||
|
||||
@Autowired
|
||||
protected GridFsOperations operations;
|
||||
|
||||
@Autowired
|
||||
protected RolloutGroupRepository rolloutGroupRepository;
|
||||
|
||||
@Autowired
|
||||
protected RolloutRepository rolloutRepository;
|
||||
|
||||
@Autowired
|
||||
protected TenantAwareCacheManager cacheManager;
|
||||
|
||||
private static CIMySqlTestDatabase tesdatabase;
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass() {
|
||||
createTestdatabaseAndStart();
|
||||
}
|
||||
|
||||
private static void createTestdatabaseAndStart() {
|
||||
if ("MYSQL".equals(System.getProperty("spring.jpa.database"))) {
|
||||
tesdatabase = new CIMySqlTestDatabase();
|
||||
tesdatabase.before();
|
||||
}
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterClass() {
|
||||
if (tesdatabase != null) {
|
||||
tesdatabase.after();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -29,7 +29,7 @@ import ru.yandex.qatools.allure.annotations.Stories;
|
||||
*/
|
||||
@Features("Component Tests - Repository")
|
||||
@Stories("Artifact Management")
|
||||
public class ArtifactManagementNoMongoDbTest extends AbstractIntegrationTest {
|
||||
public class ArtifactManagementNoMongoDbTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
@BeforeClass
|
||||
public static void initialize() {
|
||||
|
||||
@@ -32,6 +32,7 @@ import org.eclipse.hawkbit.repository.model.Artifact;
|
||||
import org.eclipse.hawkbit.repository.model.ExternalArtifactProvider;
|
||||
import org.eclipse.hawkbit.repository.model.LocalArtifact;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.util.WithUser;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.data.mongodb.core.query.Criteria;
|
||||
@@ -50,7 +51,7 @@ import ru.yandex.qatools.allure.annotations.Stories;
|
||||
*/
|
||||
@Features("Component Tests - Repository")
|
||||
@Stories("Artifact Management")
|
||||
public class ArtifactManagementTest extends AbstractIntegrationTestWithMongoDB {
|
||||
public class ArtifactManagementTest extends AbstractJpaIntegrationTestWithMongoDB {
|
||||
public ArtifactManagementTest() {
|
||||
LOG = LoggerFactory.getLogger(ArtifactManagementTest.class);
|
||||
}
|
||||
|
||||
@@ -33,14 +33,13 @@ import ru.yandex.qatools.allure.annotations.Stories;
|
||||
|
||||
@Features("Component Tests - Repository")
|
||||
@Stories("Controller Management")
|
||||
public class ControllerManagementTest extends AbstractIntegrationTest {
|
||||
public class ControllerManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
@Test
|
||||
@Description("Controller adds a new action status.")
|
||||
public void controllerAddsActionStatus() {
|
||||
final Target target = new JpaTarget("4712");
|
||||
final DistributionSet ds = TestDataUtil.generateDistributionSet("", softwareManagement,
|
||||
distributionSetManagement);
|
||||
final DistributionSet ds = testdataFactory.createDistributionSet("");
|
||||
Target savedTarget = targetManagement.createTarget(target);
|
||||
|
||||
final List<Target> toAssign = new ArrayList<>();
|
||||
@@ -99,8 +98,7 @@ public class ControllerManagementTest extends AbstractIntegrationTest {
|
||||
|
||||
// mock
|
||||
final Target target = new JpaTarget("Rabbit");
|
||||
final DistributionSet ds = TestDataUtil.generateDistributionSet("", softwareManagement,
|
||||
distributionSetManagement);
|
||||
final DistributionSet ds = testdataFactory.createDistributionSet("");
|
||||
Target savedTarget = targetManagement.createTarget(target);
|
||||
final List<Target> toAssign = new ArrayList<>();
|
||||
toAssign.add(savedTarget);
|
||||
|
||||
@@ -67,7 +67,7 @@ import ru.yandex.qatools.allure.annotations.Stories;
|
||||
*/
|
||||
@Features("Component Tests - Repository")
|
||||
@Stories("Deployment Management")
|
||||
public class DeploymentManagementTest extends AbstractIntegrationTest {
|
||||
public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private EventBus eventBus;
|
||||
@@ -75,9 +75,9 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
|
||||
@Test
|
||||
@Description("Test verifies that the repistory retrieves the action including all defined (lazy) details.")
|
||||
public void findActionWithLazyDetails() {
|
||||
final DistributionSet testDs = TestDataUtil.generateDistributionSet("TestDs", "1.0", softwareManagement,
|
||||
distributionSetManagement, new ArrayList<DistributionSetTag>());
|
||||
final List<Target> testTarget = targetManagement.createTargets(TestDataUtil.generateTargets(1));
|
||||
final DistributionSet testDs = testdataFactory.createDistributionSet("TestDs", "1.0",
|
||||
new ArrayList<DistributionSetTag>());
|
||||
final List<Target> testTarget = testdataFactory.createTargets(1);
|
||||
// one action with one action status is generated
|
||||
final Long actionId = deploymentManagement.assignDistributionSet(testDs, testTarget).getActions().get(0);
|
||||
final Action action = deploymentManagement.findActionWithDetails(actionId);
|
||||
@@ -91,9 +91,9 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
|
||||
@Test
|
||||
@Description("Test verifies that the custom query to find all actions include the count of action status is working correctly")
|
||||
public void findActionsWithStatusCountByTarget() {
|
||||
final DistributionSet testDs = TestDataUtil.generateDistributionSet("TestDs", "1.0", softwareManagement,
|
||||
distributionSetManagement, new ArrayList<DistributionSetTag>());
|
||||
final List<Target> testTarget = targetManagement.createTargets(TestDataUtil.generateTargets(1));
|
||||
final DistributionSet testDs = testdataFactory.createDistributionSet("TestDs", "1.0",
|
||||
new ArrayList<DistributionSetTag>());
|
||||
final List<Target> testTarget = testdataFactory.createTargets(1);
|
||||
// one action with one action status is generated
|
||||
final Action action = deploymentManagement.findActionWithDetails(
|
||||
deploymentManagement.assignDistributionSet(testDs, testTarget).getActions().get(0));
|
||||
@@ -114,8 +114,8 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
|
||||
public void assignAndUnassignDistributionSetToTag() {
|
||||
final List<Long> assignDS = new ArrayList<>();
|
||||
for (int i = 0; i < 4; i++) {
|
||||
assignDS.add(TestDataUtil.generateDistributionSet("DS" + i, "1.0", softwareManagement,
|
||||
distributionSetManagement, new ArrayList<DistributionSetTag>()).getId());
|
||||
assignDS.add(testdataFactory.createDistributionSet("DS" + i, "1.0", new ArrayList<DistributionSetTag>())
|
||||
.getId());
|
||||
}
|
||||
// not exists
|
||||
assignDS.add(Long.valueOf(100));
|
||||
@@ -154,14 +154,13 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
|
||||
@Description("Test verifies that an assignment with automatic cancelation works correctly even if the update is split into multiple partitions on the database.")
|
||||
public void multiAssigmentHistoryOverMultiplePagesResultsInTwoActiveAction() {
|
||||
|
||||
final DistributionSet cancelDs = TestDataUtil.generateDistributionSet("Canceled DS", "1.0", softwareManagement,
|
||||
distributionSetManagement, new ArrayList<DistributionSetTag>());
|
||||
final DistributionSet cancelDs = testdataFactory.createDistributionSet("Canceled DS", "1.0",
|
||||
new ArrayList<DistributionSetTag>());
|
||||
|
||||
final DistributionSet cancelDs2 = TestDataUtil.generateDistributionSet("Canceled DS", "1.2", softwareManagement,
|
||||
distributionSetManagement, new ArrayList<DistributionSetTag>());
|
||||
final DistributionSet cancelDs2 = testdataFactory.createDistributionSet("Canceled DS", "1.2",
|
||||
new ArrayList<DistributionSetTag>());
|
||||
|
||||
List<Target> targets = targetManagement
|
||||
.createTargets(TestDataUtil.generateTargets(Constants.MAX_ENTRIES_IN_STATEMENT + 10));
|
||||
List<Target> targets = testdataFactory.createTargets(Constants.MAX_ENTRIES_IN_STATEMENT + 10);
|
||||
|
||||
targets = deploymentManagement.assignDistributionSet(cancelDs, targets).getAssignedEntity();
|
||||
targets = deploymentManagement.assignDistributionSet(cancelDs2, targets).getAssignedEntity();
|
||||
@@ -179,15 +178,12 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
|
||||
+ "also the target goes back to IN_SYNC as no open action is left.")
|
||||
public void manualCancelWithMultipleAssignmentsCancelLastOneFirst() {
|
||||
JpaTarget target = new JpaTarget("4712");
|
||||
final JpaDistributionSet dsFirst = TestDataUtil.generateDistributionSet("", softwareManagement,
|
||||
distributionSetManagement, true);
|
||||
final DistributionSet dsFirst = testdataFactory.createDistributionSet("", true);
|
||||
dsFirst.setRequiredMigrationStep(true);
|
||||
final JpaDistributionSet dsSecond = TestDataUtil.generateDistributionSet("2", softwareManagement,
|
||||
distributionSetManagement, true);
|
||||
final JpaDistributionSet dsInstalled = TestDataUtil.generateDistributionSet("installed", softwareManagement,
|
||||
distributionSetManagement, true);
|
||||
final DistributionSet dsSecond = testdataFactory.createDistributionSet("2", true);
|
||||
final DistributionSet dsInstalled = testdataFactory.createDistributionSet("installed", true);
|
||||
|
||||
((JpaTargetInfo) target.getTargetInfo()).setInstalledDistributionSet(dsInstalled);
|
||||
((JpaTargetInfo) target.getTargetInfo()).setInstalledDistributionSet((JpaDistributionSet) dsInstalled);
|
||||
target = (JpaTarget) targetManagement.createTarget(target);
|
||||
|
||||
// check initial status
|
||||
@@ -236,15 +232,12 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
|
||||
+ "also the target goes back to IN_SYNC as no open action is left.")
|
||||
public void manualCancelWithMultipleAssignmentsCancelMiddleOneFirst() {
|
||||
JpaTarget target = new JpaTarget("4712");
|
||||
final JpaDistributionSet dsFirst = TestDataUtil.generateDistributionSet("", softwareManagement,
|
||||
distributionSetManagement, true);
|
||||
final DistributionSet dsFirst = testdataFactory.createDistributionSet("", true);
|
||||
dsFirst.setRequiredMigrationStep(true);
|
||||
final JpaDistributionSet dsSecond = TestDataUtil.generateDistributionSet("2", softwareManagement,
|
||||
distributionSetManagement, true);
|
||||
final JpaDistributionSet dsInstalled = TestDataUtil.generateDistributionSet("installed", softwareManagement,
|
||||
distributionSetManagement, true);
|
||||
final DistributionSet dsSecond = testdataFactory.createDistributionSet("2", true);
|
||||
final DistributionSet dsInstalled = testdataFactory.createDistributionSet("installed", true);
|
||||
|
||||
((JpaTargetInfo) target.getTargetInfo()).setInstalledDistributionSet(dsInstalled);
|
||||
((JpaTargetInfo) target.getTargetInfo()).setInstalledDistributionSet((JpaDistributionSet) dsInstalled);
|
||||
target = (JpaTarget) targetManagement.createTarget(target);
|
||||
|
||||
// check initial status
|
||||
@@ -295,13 +288,11 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
|
||||
public void forceQuitSetActionToInactive() throws InterruptedException {
|
||||
|
||||
JpaTarget target = new JpaTarget("4712");
|
||||
final JpaDistributionSet dsInstalled = TestDataUtil.generateDistributionSet("installed", softwareManagement,
|
||||
distributionSetManagement, true);
|
||||
((JpaTargetInfo) target.getTargetInfo()).setInstalledDistributionSet(dsInstalled);
|
||||
final DistributionSet dsInstalled = testdataFactory.createDistributionSet("installed", true);
|
||||
((JpaTargetInfo) target.getTargetInfo()).setInstalledDistributionSet((JpaDistributionSet) dsInstalled);
|
||||
target = (JpaTarget) targetManagement.createTarget(target);
|
||||
|
||||
final JpaDistributionSet ds = TestDataUtil.generateDistributionSet("newDS", softwareManagement,
|
||||
distributionSetManagement, true);
|
||||
final DistributionSet ds = testdataFactory.createDistributionSet("newDS", true);
|
||||
ds.setRequiredMigrationStep(true);
|
||||
|
||||
// verify initial status
|
||||
@@ -336,14 +327,12 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
|
||||
@Description("Force Quit an not canceled Assignment. Expected behaviour is that the action can not be force quit and there is thrown an exception.")
|
||||
public void forceQuitNotAllowedThrowsException() {
|
||||
|
||||
JpaTarget target = new JpaTarget("4712");
|
||||
final JpaDistributionSet dsInstalled = TestDataUtil.generateDistributionSet("installed", softwareManagement,
|
||||
distributionSetManagement, true);
|
||||
((JpaTargetInfo) target.getTargetInfo()).setInstalledDistributionSet(dsInstalled);
|
||||
target = (JpaTarget) targetManagement.createTarget(target);
|
||||
Target target = new JpaTarget("4712");
|
||||
final DistributionSet dsInstalled = testdataFactory.createDistributionSet("installed", true);
|
||||
((JpaTargetInfo) target.getTargetInfo()).setInstalledDistributionSet((JpaDistributionSet) dsInstalled);
|
||||
target = targetManagement.createTarget(target);
|
||||
|
||||
final JpaDistributionSet ds = TestDataUtil.generateDistributionSet("newDS", softwareManagement,
|
||||
distributionSetManagement, true);
|
||||
final DistributionSet ds = testdataFactory.createDistributionSet("newDS", true);
|
||||
ds.setRequiredMigrationStep(true);
|
||||
|
||||
// verify initial status
|
||||
@@ -364,14 +353,16 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
|
||||
}
|
||||
}
|
||||
|
||||
private Action assignSet(final JpaTarget target, final JpaDistributionSet ds) {
|
||||
private Action assignSet(final Target target, final DistributionSet ds) {
|
||||
deploymentManagement.assignDistributionSet(ds.getId(), new String[] { target.getControllerId() });
|
||||
assertThat(
|
||||
targetManagement.findTargetByControllerID(target.getControllerId()).getTargetInfo().getUpdateStatus())
|
||||
.as("wrong update status").isEqualTo(TargetUpdateStatus.PENDING);
|
||||
assertThat(targetManagement.findTargetByControllerID(target.getControllerId()).getAssignedDistributionSet())
|
||||
.as("wrong assigned ds").isEqualTo(ds);
|
||||
final Action action = actionRepository.findByTargetAndDistributionSet(pageReq, target, ds).getContent().get(0);
|
||||
final Action action = actionRepository
|
||||
.findByTargetAndDistributionSet(pageReq, (JpaTarget) target, (JpaDistributionSet) ds).getContent()
|
||||
.get(0);
|
||||
assertThat(action).as("action should not be null").isNotNull();
|
||||
return action;
|
||||
}
|
||||
@@ -392,14 +383,13 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
|
||||
|
||||
final String myCtrlIDPref = "myCtrlID";
|
||||
final Iterable<Target> savedNakedTargets = targetManagement
|
||||
.createTargets(TestDataUtil.buildTargetFixtures(10, myCtrlIDPref, "first description"));
|
||||
.createTargets(testdataFactory.generateTargets(10, myCtrlIDPref, "first description"));
|
||||
|
||||
final String myDeployedCtrlIDPref = "myDeployedCtrlID";
|
||||
List<Target> savedDeployedTargets = targetManagement
|
||||
.createTargets(TestDataUtil.buildTargetFixtures(20, myDeployedCtrlIDPref, "first description"));
|
||||
.createTargets(testdataFactory.generateTargets(20, myDeployedCtrlIDPref, "first description"));
|
||||
|
||||
final DistributionSet ds = TestDataUtil.generateDistributionSet("", softwareManagement,
|
||||
distributionSetManagement);
|
||||
final DistributionSet ds = testdataFactory.createDistributionSet("");
|
||||
|
||||
deploymentManagement.assignDistributionSet(ds, savedDeployedTargets);
|
||||
|
||||
@@ -446,7 +436,7 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
|
||||
final EventHandlerMock eventHandlerMock = new EventHandlerMock(0);
|
||||
eventBus.register(eventHandlerMock);
|
||||
|
||||
final List<Target> targets = targetManagement.createTargets(TestDataUtil.generateTargets(10));
|
||||
final List<Target> targets = testdataFactory.createTargets(10);
|
||||
|
||||
final SoftwareModule ah = softwareManagement
|
||||
.createSoftwareModule(new JpaSoftwareModule(appType, "agent-hub", "1.0.1", null, ""));
|
||||
@@ -657,7 +647,7 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
|
||||
final DeploymentResult deploymentResult = prepareComplexRepo(undeployedTargetPrefix, noOfUndeployedTargets,
|
||||
deployedTargetPrefix, noOfDeployedTargets, noOfDistributionSets, "myTestDS");
|
||||
|
||||
DistributionSet dsA = TestDataUtil.generateDistributionSet("", softwareManagement, distributionSetManagement);
|
||||
DistributionSet dsA = testdataFactory.createDistributionSet("");
|
||||
|
||||
distributionSetManagement.deleteDistributionSet(dsA.getId());
|
||||
dsA = distributionSetManagement.findDistributionSetById(dsA.getId());
|
||||
@@ -761,12 +751,9 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
|
||||
@Description("Testing if changing target and the status without refreshing the entities from the DB (e.g. concurrent changes from UI and from controller) works")
|
||||
public void alternatingAssignmentAndAddUpdateActionStatus() {
|
||||
|
||||
final JpaDistributionSet dsA = TestDataUtil.generateDistributionSet("a", softwareManagement,
|
||||
distributionSetManagement);
|
||||
final JpaDistributionSet dsB = TestDataUtil.generateDistributionSet("b", softwareManagement,
|
||||
distributionSetManagement);
|
||||
Target targ = targetManagement
|
||||
.createTarget(TestDataUtil.buildTargetFixture("target-id-A", "first description"));
|
||||
final DistributionSet dsA = testdataFactory.createDistributionSet("a");
|
||||
final DistributionSet dsB = testdataFactory.createDistributionSet("b");
|
||||
Target targ = targetManagement.createTarget(testdataFactory.generateTarget("target-id-A", "first description"));
|
||||
|
||||
List<Target> targs = new ArrayList<>();
|
||||
targs.add(targ);
|
||||
@@ -793,7 +780,7 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
|
||||
assertThat(deploymentManagement.findActiveActionsByTarget(targ).get(0).getDistributionSet())
|
||||
.as("Installed distribution set of action should be null").isNotNull();
|
||||
|
||||
final Page<Action> updAct = actionRepository.findByDistributionSet(pageReq, dsA);
|
||||
final Page<Action> updAct = actionRepository.findByDistributionSet(pageReq, (JpaDistributionSet) dsA);
|
||||
final Action action = updAct.getContent().get(0);
|
||||
action.setStatus(Status.FINISHED);
|
||||
final ActionStatus statusMessage = new JpaActionStatus((JpaAction) action, Status.FINISHED,
|
||||
@@ -831,11 +818,9 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
|
||||
@Description("The test verfies that the DS itself is not changed because of an target assignment"
|
||||
+ " which is a relationship but not a changed on the entity itself..")
|
||||
public void checkThatDsRevisionsIsNotChangedWithTargetAssignment() {
|
||||
final DistributionSet dsA = TestDataUtil.generateDistributionSet("a", softwareManagement,
|
||||
distributionSetManagement);
|
||||
TestDataUtil.generateDistributionSet("b", softwareManagement, distributionSetManagement);
|
||||
Target targ = targetManagement
|
||||
.createTarget(TestDataUtil.buildTargetFixture("target-id-A", "first description"));
|
||||
final DistributionSet dsA = testdataFactory.createDistributionSet("a");
|
||||
testdataFactory.createDistributionSet("b");
|
||||
Target targ = targetManagement.createTarget(testdataFactory.generateTarget("target-id-A", "first description"));
|
||||
|
||||
assertThat(dsA.getOptLockRevision()).as("lock revision is wrong").isEqualTo(
|
||||
distributionSetManagement.findDistributionSetByIdWithDetails(dsA.getId()).getOptLockRevision());
|
||||
@@ -854,8 +839,7 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
|
||||
public void forceSoftAction() {
|
||||
// prepare
|
||||
final Target target = targetManagement.createTarget(new JpaTarget("knownControllerId"));
|
||||
final DistributionSet ds = TestDataUtil.generateDistributionSet("a", softwareManagement,
|
||||
distributionSetManagement);
|
||||
final DistributionSet ds = testdataFactory.createDistributionSet("a");
|
||||
// assign ds to create an action
|
||||
final DistributionSetAssignmentResult assignDistributionSet = deploymentManagement.assignDistributionSet(
|
||||
ds.getId(), ActionType.SOFT, org.eclipse.hawkbit.repository.model.Constants.NO_FORCE_TIME,
|
||||
@@ -878,8 +862,7 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
|
||||
public void forceAlreadyForcedActionNothingChanges() {
|
||||
// prepare
|
||||
final Target target = targetManagement.createTarget(new JpaTarget("knownControllerId"));
|
||||
final DistributionSet ds = TestDataUtil.generateDistributionSet("a", softwareManagement,
|
||||
distributionSetManagement);
|
||||
final DistributionSet ds = testdataFactory.createDistributionSet("a");
|
||||
// assign ds to create an action
|
||||
final DistributionSetAssignmentResult assignDistributionSet = deploymentManagement.assignDistributionSet(
|
||||
ds.getId(), ActionType.FORCED, org.eclipse.hawkbit.repository.model.Constants.NO_FORCE_TIME,
|
||||
@@ -926,14 +909,14 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
|
||||
final String deployedTargetPrefix, final int noOfDeployedTargets, final int noOfDistributionSets,
|
||||
final String distributionSetPrefix) {
|
||||
final Iterable<Target> nakedTargets = targetManagement.createTargets(
|
||||
TestDataUtil.buildTargetFixtures(noOfUndeployedTargets, undeployedTargetPrefix, "first description"));
|
||||
testdataFactory.generateTargets(noOfUndeployedTargets, undeployedTargetPrefix, "first description"));
|
||||
|
||||
List<Target> deployedTargets = targetManagement.createTargets(
|
||||
TestDataUtil.buildTargetFixtures(noOfDeployedTargets, deployedTargetPrefix, "first description"));
|
||||
testdataFactory.generateTargets(noOfDeployedTargets, deployedTargetPrefix, "first description"));
|
||||
|
||||
// creating 10 DistributionSets
|
||||
final Collection<DistributionSet> dsList = (Collection) TestDataUtil.generateDistributionSets(
|
||||
distributionSetPrefix, noOfDistributionSets, softwareManagement, distributionSetManagement);
|
||||
final Collection<DistributionSet> dsList = testdataFactory.createDistributionSets(distributionSetPrefix,
|
||||
noOfDistributionSets);
|
||||
String time = String.valueOf(System.currentTimeMillis());
|
||||
time = time.substring(time.length() - 5);
|
||||
|
||||
|
||||
@@ -31,14 +31,15 @@ import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.Action.Status;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetFilter.DistributionSetFilterBuilder;
|
||||
import org.eclipse.hawkbit.repository.model.ActionStatus;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetFilter.DistributionSetFilterBuilder;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetMetadata;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetTag;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetType;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.util.WithUser;
|
||||
import org.fest.assertions.core.Condition;
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.domain.Page;
|
||||
@@ -56,7 +57,7 @@ import ru.yandex.qatools.allure.annotations.Stories;
|
||||
*/
|
||||
@Features("Component Tests - Repository")
|
||||
@Stories("DistributionSet Management")
|
||||
public class DistributionSetManagementTest extends AbstractIntegrationTest {
|
||||
public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
@Test
|
||||
@Description("Tests the successfull module update of unused distribution set type which is in fact allowed.")
|
||||
@@ -178,10 +179,10 @@ public class DistributionSetManagementTest extends AbstractIntegrationTest {
|
||||
@Test
|
||||
@Description("Ensures that it is not possible to create a DS that already exists (unique constraint is on name,version for DS).")
|
||||
public void createDuplicateDistributionSetsFailsWithException() {
|
||||
TestDataUtil.generateDistributionSet("a", softwareManagement, distributionSetManagement);
|
||||
testdataFactory.createDistributionSet("a");
|
||||
|
||||
try {
|
||||
TestDataUtil.generateDistributionSet("a", softwareManagement, distributionSetManagement);
|
||||
testdataFactory.createDistributionSet("a");
|
||||
fail("Should not have worked as DS with same UK already exists.");
|
||||
} catch (final EntityAlreadyExistsException e) {
|
||||
|
||||
@@ -239,8 +240,7 @@ public class DistributionSetManagementTest extends AbstractIntegrationTest {
|
||||
final String knownKey = "dsMetaKnownKey";
|
||||
final String knownValue = "dsMetaKnownValue";
|
||||
|
||||
final DistributionSet ds = TestDataUtil.generateDistributionSet("testDs", softwareManagement,
|
||||
distributionSetManagement);
|
||||
final DistributionSet ds = testdataFactory.createDistributionSet("testDs");
|
||||
|
||||
final DistributionSetMetadata metadata = new JpaDistributionSetMetadata(knownKey, ds, knownValue);
|
||||
final JpaDistributionSetMetadata createdMetadata = (JpaDistributionSetMetadata) distributionSetManagement
|
||||
@@ -262,8 +262,7 @@ public class DistributionSetManagementTest extends AbstractIntegrationTest {
|
||||
SoftwareModule ah2 = new JpaSoftwareModule(appType, "agent-hub2", "1.0.5", null, "");
|
||||
SoftwareModule os2 = new JpaSoftwareModule(osType, "poky2", "3.0.3", null, "");
|
||||
|
||||
DistributionSet ds = TestDataUtil.generateDistributionSet("ds-1", softwareManagement,
|
||||
distributionSetManagement);
|
||||
DistributionSet ds = testdataFactory.createDistributionSet("ds-1");
|
||||
|
||||
ah2 = softwareManagement.createSoftwareModule(ah2);
|
||||
os2 = softwareManagement.createSoftwareModule(os2);
|
||||
@@ -348,7 +347,7 @@ public class DistributionSetManagementTest extends AbstractIntegrationTest {
|
||||
SoftwareModule os2 = new JpaSoftwareModule(osType, "poky2", "3.0.3", null, "");
|
||||
final SoftwareModule app2 = new JpaSoftwareModule(appType, "app2", "3.0.3", null, "");
|
||||
|
||||
DistributionSet ds = TestDataUtil.generateDistributionSet("", softwareManagement, distributionSetManagement);
|
||||
DistributionSet ds = testdataFactory.createDistributionSet("");
|
||||
|
||||
os2 = softwareManagement.createSoftwareModule(os2);
|
||||
|
||||
@@ -387,8 +386,7 @@ public class DistributionSetManagementTest extends AbstractIntegrationTest {
|
||||
final String knownUpdateValue = "myNewUpdatedValue";
|
||||
|
||||
// create a DS
|
||||
final DistributionSet ds = TestDataUtil.generateDistributionSet("testDs", softwareManagement,
|
||||
distributionSetManagement);
|
||||
final DistributionSet ds = testdataFactory.createDistributionSet("testDs");
|
||||
// initial opt lock revision must be zero
|
||||
assertThat(ds.getOptLockRevision()).isEqualTo(1L);
|
||||
|
||||
@@ -427,13 +425,12 @@ public class DistributionSetManagementTest extends AbstractIntegrationTest {
|
||||
@Description("Tests that a DS queue is possible where the result is ordered by the target assignment, i.e. assigned first in the list.")
|
||||
public void findDistributionSetsAllOrderedByLinkTarget() {
|
||||
|
||||
final List<JpaDistributionSet> buildDistributionSets = TestDataUtil.generateDistributionSets("dsOrder", 10,
|
||||
softwareManagement, distributionSetManagement);
|
||||
final List<DistributionSet> buildDistributionSets = testdataFactory.createDistributionSets("dsOrder", 10);
|
||||
|
||||
final List<Target> buildTargetFixtures = targetManagement
|
||||
.createTargets(TestDataUtil.buildTargetFixtures(5, "tOrder", "someDesc"));
|
||||
.createTargets(testdataFactory.generateTargets(5, "tOrder", "someDesc"));
|
||||
|
||||
final Iterator<JpaDistributionSet> dsIterator = buildDistributionSets.iterator();
|
||||
final Iterator<DistributionSet> dsIterator = buildDistributionSets.iterator();
|
||||
final Iterator<Target> tIterator = buildTargetFixtures.iterator();
|
||||
final DistributionSet dsFirst = dsIterator.next();
|
||||
final DistributionSet dsSecond = dsIterator.next();
|
||||
@@ -482,12 +479,9 @@ public class DistributionSetManagementTest extends AbstractIntegrationTest {
|
||||
final DistributionSetTag dsTagD = tagManagement
|
||||
.createDistributionSetTag(new JpaDistributionSetTag("DistributionSetTag-D"));
|
||||
|
||||
Collection<DistributionSet> ds100Group1 = (Collection) TestDataUtil.generateDistributionSets("", 100,
|
||||
softwareManagement, distributionSetManagement);
|
||||
Collection<DistributionSet> ds100Group2 = (Collection) TestDataUtil.generateDistributionSets("test2", 100,
|
||||
softwareManagement, distributionSetManagement);
|
||||
DistributionSet dsDeleted = TestDataUtil.generateDistributionSet("deleted", softwareManagement,
|
||||
distributionSetManagement);
|
||||
Collection<DistributionSet> ds100Group1 = testdataFactory.createDistributionSets("", 100);
|
||||
Collection<DistributionSet> ds100Group2 = testdataFactory.createDistributionSets("test2", 100);
|
||||
DistributionSet dsDeleted = testdataFactory.createDistributionSet("deleted");
|
||||
final DistributionSet dsInComplete = distributionSetManagement
|
||||
.createDistributionSet(new JpaDistributionSet("notcomplete", "1", "", standardDsType, null));
|
||||
|
||||
@@ -498,8 +492,7 @@ public class DistributionSetManagementTest extends AbstractIntegrationTest {
|
||||
final DistributionSet dsNewType = distributionSetManagement
|
||||
.createDistributionSet(new JpaDistributionSet("newtype", "1", "", newType, dsDeleted.getModules()));
|
||||
|
||||
deploymentManagement.assignDistributionSet(dsDeleted,
|
||||
targetManagement.createTargets(Lists.newArrayList(TestDataUtil.generateTargets(5))));
|
||||
deploymentManagement.assignDistributionSet(dsDeleted, Lists.newArrayList(testdataFactory.createTargets(5)));
|
||||
distributionSetManagement.deleteDistributionSet(dsDeleted);
|
||||
dsDeleted = distributionSetManagement.findDistributionSetById(dsDeleted.getId());
|
||||
|
||||
@@ -724,7 +717,7 @@ public class DistributionSetManagementTest extends AbstractIntegrationTest {
|
||||
@Test
|
||||
@Description("Simple DS load without the related data that should be loaded lazy.")
|
||||
public void findDistributionSetsWithoutLazy() {
|
||||
TestDataUtil.generateDistributionSets(20, softwareManagement, distributionSetManagement);
|
||||
testdataFactory.createDistributionSets(20);
|
||||
|
||||
assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(pageReq, false, true))
|
||||
.hasSize(20);
|
||||
@@ -733,10 +726,8 @@ public class DistributionSetManagementTest extends AbstractIntegrationTest {
|
||||
@Test
|
||||
@Description("Deltes a DS that is no in use. Expected behaviour is a hard delete on the database.")
|
||||
public void deleteUnassignedDistributionSet() {
|
||||
DistributionSet ds1 = TestDataUtil.generateDistributionSet("ds-1", softwareManagement,
|
||||
distributionSetManagement);
|
||||
DistributionSet ds2 = TestDataUtil.generateDistributionSet("ds-2", softwareManagement,
|
||||
distributionSetManagement);
|
||||
DistributionSet ds1 = testdataFactory.createDistributionSet("ds-1");
|
||||
DistributionSet ds2 = testdataFactory.createDistributionSet("ds-2");
|
||||
|
||||
ds1 = distributionSetManagement.findDistributionSetByNameAndVersion(ds1.getName(), ds1.getVersion());
|
||||
ds2 = distributionSetManagement.findDistributionSetByNameAndVersion(ds2.getName(), ds2.getVersion());
|
||||
@@ -755,10 +746,8 @@ public class DistributionSetManagementTest extends AbstractIntegrationTest {
|
||||
@Description("Queries and loads the metadata related to a given software module.")
|
||||
public void findAllDistributionSetMetadataByDsId() {
|
||||
// create a DS
|
||||
DistributionSet ds1 = TestDataUtil.generateDistributionSet("testDs1", softwareManagement,
|
||||
distributionSetManagement);
|
||||
DistributionSet ds2 = TestDataUtil.generateDistributionSet("testDs2", softwareManagement,
|
||||
distributionSetManagement);
|
||||
DistributionSet ds1 = testdataFactory.createDistributionSet("testDs1");
|
||||
DistributionSet ds2 = testdataFactory.createDistributionSet("testDs2");
|
||||
|
||||
for (int index = 0; index < 10; index++) {
|
||||
|
||||
@@ -791,12 +780,9 @@ public class DistributionSetManagementTest extends AbstractIntegrationTest {
|
||||
@Description("Deltes a DS that is no in use. Expected behaviour is a soft delete on the database, i.e. only marked as "
|
||||
+ "deleted, kept eas refernce and unavailable for future use..")
|
||||
public void deleteAssignedDistributionSet() {
|
||||
DistributionSet ds1 = TestDataUtil.generateDistributionSet("ds-1", softwareManagement,
|
||||
distributionSetManagement);
|
||||
DistributionSet ds2 = TestDataUtil.generateDistributionSet("ds-2", softwareManagement,
|
||||
distributionSetManagement);
|
||||
DistributionSet dsAssigned = TestDataUtil.generateDistributionSet("ds-3", softwareManagement,
|
||||
distributionSetManagement);
|
||||
DistributionSet ds1 = testdataFactory.createDistributionSet("ds-1");
|
||||
DistributionSet ds2 = testdataFactory.createDistributionSet("ds-2");
|
||||
DistributionSet dsAssigned = testdataFactory.createDistributionSet("ds-3");
|
||||
|
||||
ds1 = distributionSetManagement.findDistributionSetByNameAndVersion(ds1.getName(), ds1.getVersion());
|
||||
ds2 = distributionSetManagement.findDistributionSetByNameAndVersion(ds2.getName(), ds2.getVersion());
|
||||
|
||||
@@ -1,75 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.ServerSocket;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class FreePortFileWriter {
|
||||
|
||||
private final String filePortPath;
|
||||
private final int from;
|
||||
private final int to;
|
||||
|
||||
/**
|
||||
* @param from
|
||||
* @param to
|
||||
*/
|
||||
public FreePortFileWriter(final int from, final int to, final String filePortPath) {
|
||||
this.from = from;
|
||||
this.to = to;
|
||||
this.filePortPath = filePortPath;
|
||||
}
|
||||
|
||||
public int getPort() {
|
||||
return findFree();
|
||||
}
|
||||
|
||||
protected int findFree() {
|
||||
for (int i = from; i <= to; i++) {
|
||||
if (isFree(i)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
throw new RuntimeException("No free port in range " + from + ":" + to);
|
||||
}
|
||||
|
||||
boolean isFree(final int port) {
|
||||
try {
|
||||
final File portFile = new File(filePortPath + File.separator + port + ".port");
|
||||
portFile.getParentFile().mkdirs();
|
||||
if (portFile.exists()) {
|
||||
return false;
|
||||
} else {
|
||||
boolean isFree = false;
|
||||
final ServerSocket sock = new ServerSocket();
|
||||
sock.setReuseAddress(true);
|
||||
sock.bind(new InetSocketAddress(port));
|
||||
if (portFile.createNewFile()) {
|
||||
portFile.deleteOnExit();
|
||||
isFree = true;
|
||||
}
|
||||
sock.close();
|
||||
// is free:
|
||||
return isFree;
|
||||
// We rely on an exception thrown to determine availability or
|
||||
// not availability.
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
// not free.
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
|
||||
import org.eclipse.hawkbit.cache.TenantAwareCacheManager;
|
||||
import org.eclipse.hawkbit.repository.SystemManagement;
|
||||
import org.eclipse.hawkbit.repository.util.TestRepositoryManagement;
|
||||
import org.eclipse.hawkbit.security.SystemSecurityContext;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.mongodb.gridfs.GridFsOperations;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
public class JpaTestRepositoryManagement implements TestRepositoryManagement {
|
||||
|
||||
@PersistenceContext
|
||||
private EntityManager entityManager;
|
||||
|
||||
@Autowired
|
||||
private TargetRepository targetRepository;
|
||||
|
||||
@Autowired
|
||||
private ActionRepository actionRepository;
|
||||
|
||||
@Autowired
|
||||
private DistributionSetRepository distributionSetRepository;
|
||||
|
||||
@Autowired
|
||||
private SoftwareModuleRepository softwareModuleRepository;
|
||||
|
||||
@Autowired
|
||||
private TenantMetaDataRepository tenantMetaDataRepository;
|
||||
|
||||
@Autowired
|
||||
private DistributionSetTypeRepository distributionSetTypeRepository;
|
||||
|
||||
@Autowired
|
||||
private SoftwareModuleTypeRepository softwareModuleTypeRepository;
|
||||
|
||||
@Autowired
|
||||
private TargetTagRepository targetTagRepository;
|
||||
|
||||
@Autowired
|
||||
private DistributionSetTagRepository distributionSetTagRepository;
|
||||
|
||||
@Autowired
|
||||
private SoftwareModuleMetadataRepository softwareModuleMetadataRepository;
|
||||
|
||||
@Autowired
|
||||
private ActionStatusRepository actionStatusRepository;
|
||||
|
||||
@Autowired
|
||||
private ExternalArtifactRepository externalArtifactRepository;
|
||||
|
||||
@Autowired
|
||||
private LocalArtifactRepository artifactRepository;
|
||||
|
||||
@Autowired
|
||||
private TargetInfoRepository targetInfoRepository;
|
||||
|
||||
@Autowired
|
||||
private GridFsOperations operations;
|
||||
|
||||
@Autowired
|
||||
private RolloutGroupRepository rolloutGroupRepository;
|
||||
|
||||
@Autowired
|
||||
private RolloutRepository rolloutRepository;
|
||||
|
||||
@Autowired
|
||||
private TenantAwareCacheManager cacheManager;
|
||||
|
||||
@Autowired
|
||||
private SystemSecurityContext systemSecurityContext;
|
||||
|
||||
@Autowired
|
||||
private SystemManagement systemManagement;
|
||||
|
||||
@Override
|
||||
public void clearTestRepository() {
|
||||
deleteAllRepos();
|
||||
cacheManager.getDirectCacheNames().forEach(name -> cacheManager.getDirectCache(name).clear());
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void deleteAllRepos() {
|
||||
final List<String> tenants = systemSecurityContext.runAsSystem(() -> systemManagement.findTenants());
|
||||
tenants.forEach(tenant -> {
|
||||
try {
|
||||
systemSecurityContext.runAsSystem(() -> {
|
||||
systemManagement.deleteTenant(tenant);
|
||||
return null;
|
||||
});
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,6 @@ import org.eclipse.hawkbit.repository.DistributionSetAssignmentResult;
|
||||
import org.eclipse.hawkbit.repository.ReportManagement;
|
||||
import org.eclipse.hawkbit.repository.ReportManagement.DateTypes;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetInfo;
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
@@ -38,6 +37,9 @@ import org.eclipse.hawkbit.repository.report.model.DataReportSeries;
|
||||
import org.eclipse.hawkbit.repository.report.model.DataReportSeriesItem;
|
||||
import org.eclipse.hawkbit.repository.report.model.InnerOuterDataReportSeries;
|
||||
import org.eclipse.hawkbit.repository.report.model.SeriesTime;
|
||||
import org.eclipse.hawkbit.repository.util.TestdataFactory;
|
||||
import org.eclipse.hawkbit.repository.util.WithSpringAuthorityRule;
|
||||
import org.eclipse.hawkbit.repository.util.WithUser;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -55,7 +57,7 @@ import ru.yandex.qatools.allure.annotations.Stories;
|
||||
|
||||
@Features("Component Tests - Repository")
|
||||
@Stories("Report Management")
|
||||
public class ReportManagementTest extends AbstractIntegrationTest {
|
||||
public class ReportManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private ReportManagement reportManagement;
|
||||
@@ -128,8 +130,7 @@ public class ReportManagementTest extends AbstractIntegrationTest {
|
||||
final LocalDateTime to = LocalDateTime.now();
|
||||
final LocalDateTime from = to.minusMonths(maxMonthBackAmountReportTargets);
|
||||
|
||||
final DistributionSet distributionSet = TestDataUtil.generateDistributionSet("ds", softwareManagement,
|
||||
distributionSetManagement);
|
||||
final DistributionSet distributionSet = testdataFactory.createDistributionSet("ds");
|
||||
|
||||
final DynamicDateTimeProvider dynamicDateTimeProvider = new DynamicDateTimeProvider();
|
||||
auditingHandler.setDateTimeProvider(dynamicDateTimeProvider);
|
||||
@@ -181,21 +182,18 @@ public class ReportManagementTest extends AbstractIntegrationTest {
|
||||
final Target knownTarget4 = targetManagement.createTarget(new JpaTarget("t4"));
|
||||
final Target knownTarget5 = targetManagement.createTarget(new JpaTarget("t5"));
|
||||
|
||||
final SoftwareModule ah = softwareManagement
|
||||
.createSoftwareModule(new JpaSoftwareModule(appType, "agent-hub", "1.0.1", null, ""));
|
||||
final SoftwareModule jvm = softwareManagement
|
||||
.createSoftwareModule(new JpaSoftwareModule(runtimeType, "oracle-jre", "1.7.2", null, ""));
|
||||
final SoftwareModule os = softwareManagement
|
||||
.createSoftwareModule(new JpaSoftwareModule(osType, "poky", "3.0.2", null, ""));
|
||||
final SoftwareModule ah = testdataFactory.createSoftwareModule(TestdataFactory.SM_TYPE_APP);
|
||||
final SoftwareModule jvm = testdataFactory.createSoftwareModule(TestdataFactory.SM_TYPE_RT);
|
||||
final SoftwareModule os = testdataFactory.createSoftwareModule(TestdataFactory.SM_TYPE_OS);
|
||||
|
||||
final DistributionSet distributionSet1 = distributionSetManagement
|
||||
.createDistributionSet(TestDataUtil.buildDistributionSet("ds1", "0.0.0", standardDsType, os, jvm, ah));
|
||||
final DistributionSet distributionSet11 = distributionSetManagement
|
||||
.createDistributionSet(TestDataUtil.buildDistributionSet("ds1", "0.0.1", standardDsType, os, jvm, ah));
|
||||
final DistributionSet distributionSet2 = distributionSetManagement
|
||||
.createDistributionSet(TestDataUtil.buildDistributionSet("ds2", "0.0.2", standardDsType, os, jvm, ah));
|
||||
final DistributionSet distributionSet3 = distributionSetManagement
|
||||
.createDistributionSet(TestDataUtil.buildDistributionSet("ds3", "0.0.3", standardDsType, os, jvm, ah));
|
||||
final DistributionSet distributionSet1 = distributionSetManagement.createDistributionSet(testdataFactory
|
||||
.generateDistributionSet("ds1", "0.0.0", standardDsType, Lists.newArrayList(os, jvm, ah)));
|
||||
final DistributionSet distributionSet11 = distributionSetManagement.createDistributionSet(testdataFactory
|
||||
.generateDistributionSet("ds1", "0.0.1", standardDsType, Lists.newArrayList(os, jvm, ah)));
|
||||
final DistributionSet distributionSet2 = distributionSetManagement.createDistributionSet(testdataFactory
|
||||
.generateDistributionSet("ds2", "0.0.2", standardDsType, Lists.newArrayList(os, jvm, ah)));
|
||||
final DistributionSet distributionSet3 = distributionSetManagement.createDistributionSet(testdataFactory
|
||||
.generateDistributionSet("ds3", "0.0.3", standardDsType, Lists.newArrayList(os, jvm, ah)));
|
||||
|
||||
// ds1(0.0.0)=[target1,target2], ds1(0.0.1)=[target3]
|
||||
deploymentManagement.assignDistributionSet(distributionSet1.getId(), knownTarget1.getControllerId());
|
||||
@@ -355,21 +353,18 @@ public class ReportManagementTest extends AbstractIntegrationTest {
|
||||
final Target knownTarget3 = targetManagement.createTarget(new JpaTarget("t3"));
|
||||
final Target knownTarget4 = targetManagement.createTarget(new JpaTarget("t4"));
|
||||
|
||||
final SoftwareModule ah = softwareManagement
|
||||
.createSoftwareModule(new JpaSoftwareModule(appType, "agent-hub", "1.0.1", null, ""));
|
||||
final SoftwareModule jvm = softwareManagement
|
||||
.createSoftwareModule(new JpaSoftwareModule(runtimeType, "oracle-jre", "1.7.2", null, ""));
|
||||
final SoftwareModule os = softwareManagement
|
||||
.createSoftwareModule(new JpaSoftwareModule(osType, "poky", "3.0.2", null, ""));
|
||||
final SoftwareModule ah = testdataFactory.createSoftwareModule(TestdataFactory.SM_TYPE_APP);
|
||||
final SoftwareModule jvm = testdataFactory.createSoftwareModule(TestdataFactory.SM_TYPE_RT);
|
||||
final SoftwareModule os = testdataFactory.createSoftwareModule(TestdataFactory.SM_TYPE_OS);
|
||||
|
||||
final DistributionSet distributionSet1 = distributionSetManagement
|
||||
.createDistributionSet(TestDataUtil.buildDistributionSet("ds1", "0.0.0", standardDsType, os, jvm, ah));
|
||||
final DistributionSet distributionSet11 = distributionSetManagement
|
||||
.createDistributionSet(TestDataUtil.buildDistributionSet("ds1", "0.0.1", standardDsType, os, jvm, ah));
|
||||
final DistributionSet distributionSet2 = distributionSetManagement
|
||||
.createDistributionSet(TestDataUtil.buildDistributionSet("ds2", "0.0.2", standardDsType, os, jvm, ah));
|
||||
final DistributionSet distributionSet3 = distributionSetManagement
|
||||
.createDistributionSet(TestDataUtil.buildDistributionSet("ds3", "0.0.3", standardDsType, os, jvm, ah));
|
||||
final DistributionSet distributionSet1 = distributionSetManagement.createDistributionSet(testdataFactory
|
||||
.generateDistributionSet("ds1", "0.0.0", standardDsType, Lists.newArrayList(os, jvm, ah)));
|
||||
final DistributionSet distributionSet11 = distributionSetManagement.createDistributionSet(testdataFactory
|
||||
.generateDistributionSet("ds1", "0.0.1", standardDsType, Lists.newArrayList(os, jvm, ah)));
|
||||
final DistributionSet distributionSet2 = distributionSetManagement.createDistributionSet(testdataFactory
|
||||
.generateDistributionSet("ds2", "0.0.2", standardDsType, Lists.newArrayList(os, jvm, ah)));
|
||||
final DistributionSet distributionSet3 = distributionSetManagement.createDistributionSet(testdataFactory
|
||||
.generateDistributionSet("ds3", "0.0.3", standardDsType, Lists.newArrayList(os, jvm, ah)));
|
||||
|
||||
// ds1(0.0.0)=[target1,target2], ds1(0.0.1)=[target3]
|
||||
deploymentManagement.assignDistributionSet(distributionSet1.getId(), knownTarget1.getControllerId());
|
||||
|
||||
@@ -22,7 +22,6 @@ import org.eclipse.hawkbit.repository.RolloutManagement;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaAction;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaRollout;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.jpa.utils.MultipleInvokeHelper;
|
||||
import org.eclipse.hawkbit.repository.jpa.utils.SuccessCondition;
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
@@ -41,6 +40,7 @@ import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
|
||||
import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus;
|
||||
import org.eclipse.hawkbit.repository.util.TestdataFactory;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Description;
|
||||
@@ -49,6 +49,8 @@ import org.springframework.data.domain.Slice;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.domain.Sort.Direction;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import ru.yandex.qatools.allure.annotations.Features;
|
||||
import ru.yandex.qatools.allure.annotations.Stories;
|
||||
|
||||
@@ -60,7 +62,7 @@ import ru.yandex.qatools.allure.annotations.Stories;
|
||||
*/
|
||||
@Features("Component Tests - Repository")
|
||||
@Stories("Rollout Management")
|
||||
public class RolloutManagementTest extends AbstractIntegrationTest {
|
||||
public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private RolloutManagement rolloutManagement;
|
||||
@@ -455,8 +457,7 @@ public class RolloutManagementTest extends AbstractIntegrationTest {
|
||||
targetToCancel.add(targetList.get(0));
|
||||
targetToCancel.add(targetList.get(1));
|
||||
targetToCancel.add(targetList.get(2));
|
||||
final DistributionSet dsForCancelTest = TestDataUtil.generateDistributionSet("dsForTest", softwareManagement,
|
||||
distributionSetManagement);
|
||||
final DistributionSet dsForCancelTest = testdataFactory.createDistributionSet("dsForTest");
|
||||
deploymentManagement.assignDistributionSet(dsForCancelTest, targetToCancel);
|
||||
// 5 targets are canceling but still have the status running and 5 are
|
||||
// still in SCHEDULED
|
||||
@@ -480,8 +481,7 @@ public class RolloutManagementTest extends AbstractIntegrationTest {
|
||||
rolloutManagement.startRollout(rolloutOne);
|
||||
rolloutOne = rolloutManagement.findRolloutById(rolloutOne.getId());
|
||||
|
||||
final DistributionSet dsForRolloutTwo = TestDataUtil.generateDistributionSet("dsForRolloutTwo",
|
||||
softwareManagement, distributionSetManagement);
|
||||
final DistributionSet dsForRolloutTwo = testdataFactory.createDistributionSet("dsForRolloutTwo");
|
||||
|
||||
final Rollout rolloutTwo = createRolloutByVariables("rolloutTwo", "This is the description for rollout two", 1,
|
||||
"controllerId==rollout-*", dsForRolloutTwo, "50", "80");
|
||||
@@ -834,7 +834,7 @@ public class RolloutManagementTest extends AbstractIntegrationTest {
|
||||
Rollout myRollout = createTestRolloutWithTargetsAndDistributionSet(amountTargetsForRollout, amountGroups,
|
||||
successCondition, errorCondition, rolloutName, rolloutName);
|
||||
|
||||
targetManagement.createTargets(TestDataUtil.buildTargetFixtures(amountOtherTargets, "others-", "rollout"));
|
||||
targetManagement.createTargets(testdataFactory.generateTargets(amountOtherTargets, "others-", "rollout"));
|
||||
|
||||
final String rsqlParam = "controllerId==*MyRoll*";
|
||||
|
||||
@@ -872,10 +872,9 @@ public class RolloutManagementTest extends AbstractIntegrationTest {
|
||||
final String errorCondition = "80";
|
||||
final String rolloutName = "rolloutTest";
|
||||
final String targetPrefixName = rolloutName;
|
||||
final DistributionSet distributionSet = TestDataUtil.generateDistributionSet("dsFor" + rolloutName,
|
||||
softwareManagement, distributionSetManagement);
|
||||
final DistributionSet distributionSet = testdataFactory.createDistributionSet("dsFor" + rolloutName);
|
||||
targetManagement.createTargets(
|
||||
TestDataUtil.buildTargetFixtures(amountTargetsForRollout, targetPrefixName + "-", targetPrefixName));
|
||||
testdataFactory.generateTargets(amountTargetsForRollout, targetPrefixName + "-", targetPrefixName));
|
||||
final RolloutGroupConditions conditions = new RolloutGroupConditionBuilder()
|
||||
.successCondition(RolloutGroupSuccessCondition.THRESHOLD, successCondition)
|
||||
.errorCondition(RolloutGroupErrorCondition.THRESHOLD, errorCondition)
|
||||
@@ -933,17 +932,14 @@ public class RolloutManagementTest extends AbstractIntegrationTest {
|
||||
private Rollout createSimpleTestRolloutWithTargetsAndDistributionSet(final int amountTargetsForRollout,
|
||||
final int amountOtherTargets, final int groupSize, final String successCondition,
|
||||
final String errorCondition) {
|
||||
final SoftwareModule ah = softwareManagement
|
||||
.createSoftwareModule(new JpaSoftwareModule(appType, "agent-hub", "1.0.1", null, ""));
|
||||
final SoftwareModule jvm = softwareManagement
|
||||
.createSoftwareModule(new JpaSoftwareModule(runtimeType, "oracle-jre", "1.7.2", null, ""));
|
||||
final SoftwareModule os = softwareManagement
|
||||
.createSoftwareModule(new JpaSoftwareModule(osType, "poky", "3.0.2", null, ""));
|
||||
final DistributionSet rolloutDS = distributionSetManagement.createDistributionSet(
|
||||
TestDataUtil.buildDistributionSet("rolloutDS", "0.0.0", standardDsType, os, jvm, ah));
|
||||
targetManagement
|
||||
.createTargets(TestDataUtil.buildTargetFixtures(amountTargetsForRollout, "rollout-", "rollout"));
|
||||
targetManagement.createTargets(TestDataUtil.buildTargetFixtures(amountOtherTargets, "others-", "rollout"));
|
||||
final SoftwareModule ah = testdataFactory.createSoftwareModule(TestdataFactory.SM_TYPE_APP);
|
||||
final SoftwareModule jvm = testdataFactory.createSoftwareModule(TestdataFactory.SM_TYPE_RT);
|
||||
final SoftwareModule os = testdataFactory.createSoftwareModule(TestdataFactory.SM_TYPE_OS);
|
||||
|
||||
final DistributionSet rolloutDS = distributionSetManagement.createDistributionSet(testdataFactory
|
||||
.generateDistributionSet("rolloutDS", "0.0.0", standardDsType, Lists.newArrayList(os, jvm, ah)));
|
||||
targetManagement.createTargets(testdataFactory.generateTargets(amountTargetsForRollout, "rollout-", "rollout"));
|
||||
targetManagement.createTargets(testdataFactory.generateTargets(amountOtherTargets, "others-", "rollout"));
|
||||
final String filterQuery = "controllerId==rollout-*";
|
||||
return createRolloutByVariables("test-rollout-name-1", "test-rollout-description-1", groupSize, filterQuery,
|
||||
rolloutDS, successCondition, errorCondition);
|
||||
@@ -952,10 +948,9 @@ public class RolloutManagementTest extends AbstractIntegrationTest {
|
||||
private Rollout createTestRolloutWithTargetsAndDistributionSet(final int amountTargetsForRollout,
|
||||
final int groupSize, final String successCondition, final String errorCondition, final String rolloutName,
|
||||
final String targetPrefixName) {
|
||||
final DistributionSet dsForRolloutTwo = TestDataUtil.generateDistributionSet("dsFor" + rolloutName,
|
||||
softwareManagement, distributionSetManagement);
|
||||
final DistributionSet dsForRolloutTwo = testdataFactory.createDistributionSet("dsFor" + rolloutName);
|
||||
targetManagement.createTargets(
|
||||
TestDataUtil.buildTargetFixtures(amountTargetsForRollout, targetPrefixName + "-", targetPrefixName));
|
||||
testdataFactory.generateTargets(amountTargetsForRollout, targetPrefixName + "-", targetPrefixName));
|
||||
return createRolloutByVariables(rolloutName, rolloutName + "description", groupSize,
|
||||
"controllerId==" + targetPrefixName + "-*", dsForRolloutTwo, successCondition, errorCondition);
|
||||
}
|
||||
|
||||
@@ -39,6 +39,7 @@ import org.eclipse.hawkbit.repository.model.SoftwareModuleMetadata;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
|
||||
import org.eclipse.hawkbit.repository.util.WithUser;
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
@@ -54,7 +55,7 @@ import ru.yandex.qatools.allure.annotations.Stories;
|
||||
|
||||
@Features("Component Tests - Repository")
|
||||
@Stories("Software Management")
|
||||
public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB {
|
||||
public class SoftwareManagementTest extends AbstractJpaIntegrationTestWithMongoDB {
|
||||
|
||||
@Test
|
||||
@Description("Try to update non updatable fields results in repository doing nothing.")
|
||||
@@ -227,8 +228,8 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB {
|
||||
|
||||
final SoftwareModule ah2 = softwareManagement
|
||||
.createSoftwareModule(new JpaSoftwareModule(appType, "agent-hub", "1.0.2", null, ""));
|
||||
JpaDistributionSet ds = (JpaDistributionSet) distributionSetManagement.createDistributionSet(
|
||||
TestDataUtil.buildDistributionSet("ds-1", "1.0.1", standardDsType, os, jvm, ah2));
|
||||
JpaDistributionSet ds = (JpaDistributionSet) distributionSetManagement.createDistributionSet(testdataFactory
|
||||
.generateDistributionSet("ds-1", "1.0.1", standardDsType, Lists.newArrayList(os, jvm, ah2)));
|
||||
|
||||
final JpaTarget target = (JpaTarget) targetManagement.createTarget(new JpaTarget("test123"));
|
||||
ds = (JpaDistributionSet) assignSet(target, ds).getDistributionSet();
|
||||
|
||||
@@ -18,6 +18,7 @@ import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.report.model.TenantUsage;
|
||||
import org.eclipse.hawkbit.repository.util.WithSpringAuthorityRule;
|
||||
import org.junit.Test;
|
||||
|
||||
import ru.yandex.qatools.allure.annotations.Description;
|
||||
@@ -26,7 +27,7 @@ import ru.yandex.qatools.allure.annotations.Stories;
|
||||
|
||||
@Features("Component Tests - Repository")
|
||||
@Stories("System Management")
|
||||
public class SystemManagementTest extends AbstractIntegrationTestWithMongoDB {
|
||||
public class SystemManagementTest extends AbstractJpaIntegrationTestWithMongoDB {
|
||||
|
||||
@Test
|
||||
@Description("Ensures that findTenants returns all tenants and not only restricted to the tenant which currently is logged in")
|
||||
@@ -108,8 +109,8 @@ public class SystemManagementTest extends AbstractIntegrationTestWithMongoDB {
|
||||
final List<Target> createdTargets = createTestTargets(targets);
|
||||
if (updates > 0) {
|
||||
for (int x = 0; x < updates; x++) {
|
||||
final DistributionSet ds = TestDataUtil.generateDistributionSet("to be deployed" + x,
|
||||
softwareManagement, distributionSetManagement, true);
|
||||
final DistributionSet ds = testdataFactory.createDistributionSet("to be deployed" + x,
|
||||
true);
|
||||
|
||||
deploymentManagement.assignDistributionSet(ds, createdTargets);
|
||||
}
|
||||
@@ -125,7 +126,7 @@ public class SystemManagementTest extends AbstractIntegrationTestWithMongoDB {
|
||||
|
||||
private List<Target> createTestTargets(final int targets) {
|
||||
return targetManagement
|
||||
.createTargets(TestDataUtil.buildTargetFixtures(targets, "testTargetOfTenant", "testTargetOfTenant"));
|
||||
.createTargets(testdataFactory.generateTargets(targets, "testTargetOfTenant", "testTargetOfTenant"));
|
||||
}
|
||||
|
||||
private void createTestArtifact(final byte[] random) {
|
||||
@@ -137,8 +138,7 @@ public class SystemManagementTest extends AbstractIntegrationTestWithMongoDB {
|
||||
}
|
||||
|
||||
private void createDeletedTestArtifact(final byte[] random) {
|
||||
final DistributionSet ds = TestDataUtil.generateDistributionSet("deleted garbage", softwareManagement,
|
||||
distributionSetManagement, true);
|
||||
final DistributionSet ds = testdataFactory.createDistributionSet("deleted garbage", true);
|
||||
ds.getModules().stream().forEach(module -> {
|
||||
artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), module.getId(), "file1", false);
|
||||
softwareManagement.deleteSoftwareModule(module);
|
||||
|
||||
@@ -23,13 +23,13 @@ import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetTag;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetFilter.DistributionSetFilterBuilder;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetTag;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetTagAssignmentResult;
|
||||
import org.eclipse.hawkbit.repository.model.Tag;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.model.TargetTag;
|
||||
import org.eclipse.hawkbit.repository.model.TargetTagAssignmentResult;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetFilter.DistributionSetFilterBuilder;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -46,7 +46,7 @@ import ru.yandex.qatools.allure.annotations.Stories;
|
||||
*/
|
||||
@Features("Component Tests - Repository")
|
||||
@Stories("Tag Management")
|
||||
public class TagManagementTest extends AbstractIntegrationTest {
|
||||
public class TagManagementTest extends AbstractJpaIntegrationTest {
|
||||
public TagManagementTest() {
|
||||
LOG = LoggerFactory.getLogger(TagManagementTest.class);
|
||||
}
|
||||
@@ -59,20 +59,13 @@ public class TagManagementTest extends AbstractIntegrationTest {
|
||||
@Test
|
||||
@Description("Full DS tag lifecycle tested. Create tags, assign them to sets and delete the tags.")
|
||||
public void createAndAssignAndDeleteDistributionSetTags() {
|
||||
final Collection<DistributionSet> dsAs = (Collection) TestDataUtil.generateDistributionSets("DS-A", 20,
|
||||
softwareManagement, distributionSetManagement);
|
||||
final Collection<DistributionSet> dsBs = (Collection) TestDataUtil.generateDistributionSets("DS-B", 10,
|
||||
softwareManagement, distributionSetManagement);
|
||||
final Collection<DistributionSet> dsCs = (Collection) TestDataUtil.generateDistributionSets("DS-C", 25,
|
||||
softwareManagement, distributionSetManagement);
|
||||
final Collection<DistributionSet> dsABs = (Collection) TestDataUtil.generateDistributionSets("DS-AB", 5,
|
||||
softwareManagement, distributionSetManagement);
|
||||
final Collection<DistributionSet> dsACs = (Collection) TestDataUtil.generateDistributionSets("DS-AC", 11,
|
||||
softwareManagement, distributionSetManagement);
|
||||
final Collection<DistributionSet> dsBCs = (Collection) TestDataUtil.generateDistributionSets("DS-BC", 13,
|
||||
softwareManagement, distributionSetManagement);
|
||||
final Collection<DistributionSet> dsABCs = (Collection) TestDataUtil.generateDistributionSets("DS-ABC", 9,
|
||||
softwareManagement, distributionSetManagement);
|
||||
final Collection<DistributionSet> dsAs = testdataFactory.createDistributionSets("DS-A", 20);
|
||||
final Collection<DistributionSet> dsBs = testdataFactory.createDistributionSets("DS-B", 10);
|
||||
final Collection<DistributionSet> dsCs = testdataFactory.createDistributionSets("DS-C", 25);
|
||||
final Collection<DistributionSet> dsABs = testdataFactory.createDistributionSets("DS-AB", 5);
|
||||
final Collection<DistributionSet> dsACs = testdataFactory.createDistributionSets("DS-AC", 11);
|
||||
final Collection<DistributionSet> dsBCs = testdataFactory.createDistributionSets("DS-BC", 13);
|
||||
final Collection<DistributionSet> dsABCs = testdataFactory.createDistributionSets("DS-ABC", 9);
|
||||
|
||||
final DistributionSetTag tagA = tagManagement.createDistributionSetTag(new JpaDistributionSetTag("A"));
|
||||
final DistributionSetTag tagB = tagManagement.createDistributionSetTag(new JpaDistributionSetTag("B"));
|
||||
@@ -169,10 +162,8 @@ public class TagManagementTest extends AbstractIntegrationTest {
|
||||
@Description("Verifies the toogle mechanism by means on assigning tag if at least on DS in the list does not have"
|
||||
+ "the tag yet. Unassign if all of them have the tag already.")
|
||||
public void assignAndUnassignDistributionSetTags() {
|
||||
final Collection<DistributionSet> groupA = (Collection) TestDataUtil.generateDistributionSets(20,
|
||||
softwareManagement, distributionSetManagement);
|
||||
final Collection<DistributionSet> groupB = (Collection) TestDataUtil.generateDistributionSets("unassigned", 20,
|
||||
softwareManagement, distributionSetManagement);
|
||||
final Collection<DistributionSet> groupA = testdataFactory.createDistributionSets(20);
|
||||
final Collection<DistributionSet> groupB = testdataFactory.createDistributionSets("unassigned", 20);
|
||||
|
||||
final DistributionSetTag tag = tagManagement
|
||||
.createDistributionSetTag(new JpaDistributionSetTag("tag1", "tagdesc1", ""));
|
||||
@@ -213,8 +204,8 @@ public class TagManagementTest extends AbstractIntegrationTest {
|
||||
@Description("Verifies the toogle mechanism by means on assigning tag if at least on target in the list does not have"
|
||||
+ "the tag yet. Unassign if all of them have the tag already.")
|
||||
public void assignAndUnassignTargetTags() {
|
||||
final List<Target> groupA = targetManagement.createTargets(TestDataUtil.generateTargets(20, ""));
|
||||
final List<Target> groupB = targetManagement.createTargets(TestDataUtil.generateTargets(20, "groupb"));
|
||||
final List<Target> groupA = targetManagement.createTargets(testdataFactory.generateTargets(20, ""));
|
||||
final List<Target> groupB = targetManagement.createTargets(testdataFactory.generateTargets(20, "groupb"));
|
||||
|
||||
final TargetTag tag = tagManagement.createTargetTag(new JpaTargetTag("tag1", "tagdesc1", ""));
|
||||
|
||||
@@ -451,8 +442,8 @@ public class TagManagementTest extends AbstractIntegrationTest {
|
||||
}
|
||||
|
||||
private List<JpaTargetTag> createTargetsWithTags() {
|
||||
final List<Target> targets = targetManagement.createTargets(TestDataUtil.generateTargets(20));
|
||||
final Iterable<TargetTag> tags = tagManagement.createTargetTags(TestDataUtil.generateTargetTags(20));
|
||||
final List<Target> targets = testdataFactory.createTargets(20);
|
||||
final Iterable<TargetTag> tags = tagManagement.createTargetTags(testdataFactory.generateTargetTags(20));
|
||||
|
||||
tags.forEach(tag -> targetManagement.toggleTagAssignment(targets, tag));
|
||||
|
||||
@@ -461,10 +452,8 @@ public class TagManagementTest extends AbstractIntegrationTest {
|
||||
|
||||
private List<DistributionSetTag> createDsSetsWithTags() {
|
||||
|
||||
final Collection<DistributionSet> sets = (Collection) TestDataUtil.generateDistributionSets(20,
|
||||
softwareManagement, distributionSetManagement);
|
||||
final Iterable<DistributionSetTag> tags = tagManagement
|
||||
.createDistributionSetTags(TestDataUtil.generateDistributionSetTags(20));
|
||||
final Collection<DistributionSet> sets = testdataFactory.createDistributionSets(20);
|
||||
final Iterable<DistributionSetTag> tags = testdataFactory.createDistributionSetTags(20);
|
||||
|
||||
tags.forEach(tag -> distributionSetManagement.toggleTagAssignment(sets, tag));
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ import ru.yandex.qatools.allure.annotations.Stories;
|
||||
*/
|
||||
@Features("Component Tests - Repository")
|
||||
@Stories("Target Filter Query Management")
|
||||
public class TargetFilterQueryManagenmentTest extends AbstractIntegrationTest {
|
||||
public class TargetFilterQueryManagenmentTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
@Test
|
||||
@Description("Test creation of target filter query.")
|
||||
|
||||
@@ -44,7 +44,7 @@ import ru.yandex.qatools.allure.annotations.Stories;
|
||||
|
||||
@Features("Component Tests - Repository")
|
||||
@Stories("Target Management Searches")
|
||||
public class TargetManagementSearchTest extends AbstractIntegrationTest {
|
||||
public class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
@Test
|
||||
@Description("Tests different parameter combinations for target search operations. "
|
||||
@@ -56,32 +56,30 @@ public class TargetManagementSearchTest extends AbstractIntegrationTest {
|
||||
final TargetTag targTagZ = tagManagement.createTargetTag(new JpaTargetTag("TargTag-Z"));
|
||||
final TargetTag targTagW = tagManagement.createTargetTag(new JpaTargetTag("TargTag-W"));
|
||||
|
||||
final DistributionSet setA = TestDataUtil.generateDistributionSet("", softwareManagement,
|
||||
distributionSetManagement);
|
||||
final DistributionSet setA = testdataFactory.createDistributionSet("");
|
||||
|
||||
final DistributionSet installedSet = TestDataUtil.generateDistributionSet("another", softwareManagement,
|
||||
distributionSetManagement);
|
||||
final DistributionSet installedSet = testdataFactory.createDistributionSet("another");
|
||||
|
||||
final String targetDsAIdPref = "targ-A";
|
||||
List<Target> targAs = targetManagement.createTargets(
|
||||
TestDataUtil.buildTargetFixtures(100, targetDsAIdPref, targetDsAIdPref.concat(" description")));
|
||||
testdataFactory.generateTargets(100, targetDsAIdPref, targetDsAIdPref.concat(" description")));
|
||||
targAs = targetManagement.toggleTagAssignment(targAs, targTagX).getAssignedEntity();
|
||||
|
||||
final String targetDsBIdPref = "targ-B";
|
||||
List<Target> targBs = targetManagement.createTargets(
|
||||
TestDataUtil.buildTargetFixtures(100, targetDsBIdPref, targetDsBIdPref.concat(" description")));
|
||||
testdataFactory.generateTargets(100, targetDsBIdPref, targetDsBIdPref.concat(" description")));
|
||||
targBs = targetManagement.toggleTagAssignment(targBs, targTagY).getAssignedEntity();
|
||||
targBs = targetManagement.toggleTagAssignment(targBs, targTagW).getAssignedEntity();
|
||||
|
||||
final String targetDsCIdPref = "targ-C";
|
||||
List<Target> targCs = targetManagement.createTargets(
|
||||
TestDataUtil.buildTargetFixtures(100, targetDsCIdPref, targetDsCIdPref.concat(" description")));
|
||||
testdataFactory.generateTargets(100, targetDsCIdPref, targetDsCIdPref.concat(" description")));
|
||||
targCs = targetManagement.toggleTagAssignment(targCs, targTagZ).getAssignedEntity();
|
||||
targCs = targetManagement.toggleTagAssignment(targCs, targTagW).getAssignedEntity();
|
||||
|
||||
final String targetDsDIdPref = "targ-D";
|
||||
final List<Target> targDs = targetManagement.createTargets(
|
||||
TestDataUtil.buildTargetFixtures(100, targetDsDIdPref, targetDsDIdPref.concat(" description")));
|
||||
testdataFactory.generateTargets(100, targetDsDIdPref, targetDsDIdPref.concat(" description")));
|
||||
|
||||
final String assignedC = targCs.iterator().next().getControllerId();
|
||||
deploymentManagement.assignDistributionSet(setA.getId(), assignedC);
|
||||
@@ -680,14 +678,13 @@ public class TargetManagementSearchTest extends AbstractIntegrationTest {
|
||||
public void targetSearchWithVariousFilterCombinationsAndOrderByDistributionSet() {
|
||||
|
||||
final List<Target> notAssigned = targetManagement
|
||||
.createTargets(TestDataUtil.buildTargetFixtures(3, "not", "first description"));
|
||||
.createTargets(testdataFactory.generateTargets(3, "not", "first description"));
|
||||
List<Target> targAssigned = targetManagement
|
||||
.createTargets(TestDataUtil.buildTargetFixtures(3, "assigned", "first description"));
|
||||
.createTargets(testdataFactory.generateTargets(3, "assigned", "first description"));
|
||||
List<Target> targInstalled = targetManagement
|
||||
.createTargets(TestDataUtil.buildTargetFixtures(3, "installed", "first description"));
|
||||
.createTargets(testdataFactory.generateTargets(3, "installed", "first description"));
|
||||
|
||||
final DistributionSet ds = TestDataUtil.generateDistributionSet("a", softwareManagement,
|
||||
distributionSetManagement);
|
||||
final DistributionSet ds = testdataFactory.createDistributionSet("a");
|
||||
|
||||
targAssigned = deploymentManagement.assignDistributionSet(ds, targAssigned).getAssignedEntity();
|
||||
targInstalled = deploymentManagement.assignDistributionSet(ds, targInstalled).getAssignedEntity();
|
||||
@@ -714,10 +711,9 @@ public class TargetManagementSearchTest extends AbstractIntegrationTest {
|
||||
@Test
|
||||
@Description("Verfies that targets with given assigned DS are returned from repository.")
|
||||
public void findTargetByAssignedDistributionSet() {
|
||||
final DistributionSet assignedSet = TestDataUtil.generateDistributionSet("", softwareManagement,
|
||||
distributionSetManagement);
|
||||
targetManagement.createTargets(TestDataUtil.generateTargets(10, "unassigned"));
|
||||
List<Target> assignedtargets = targetManagement.createTargets(TestDataUtil.generateTargets(10, "assigned"));
|
||||
final DistributionSet assignedSet = testdataFactory.createDistributionSet("");
|
||||
targetManagement.createTargets(testdataFactory.generateTargets(10, "unassigned"));
|
||||
List<Target> assignedtargets = targetManagement.createTargets(testdataFactory.generateTargets(10, "assigned"));
|
||||
|
||||
deploymentManagement.assignDistributionSet(assignedSet, assignedtargets);
|
||||
|
||||
@@ -734,12 +730,10 @@ public class TargetManagementSearchTest extends AbstractIntegrationTest {
|
||||
@Test
|
||||
@Description("Verfies that targets with given installed DS are returned from repository.")
|
||||
public void findTargetByInstalledDistributionSet() {
|
||||
final DistributionSet assignedSet = TestDataUtil.generateDistributionSet("", softwareManagement,
|
||||
distributionSetManagement);
|
||||
final DistributionSet installedSet = TestDataUtil.generateDistributionSet("another", softwareManagement,
|
||||
distributionSetManagement);
|
||||
targetManagement.createTargets(TestDataUtil.generateTargets(10, "unassigned"));
|
||||
List<Target> installedtargets = targetManagement.createTargets(TestDataUtil.generateTargets(10, "assigned"));
|
||||
final DistributionSet assignedSet = testdataFactory.createDistributionSet("");
|
||||
final DistributionSet installedSet = testdataFactory.createDistributionSet("another");
|
||||
targetManagement.createTargets(testdataFactory.generateTargets(10, "unassigned"));
|
||||
List<Target> installedtargets = targetManagement.createTargets(testdataFactory.generateTargets(10, "assigned"));
|
||||
|
||||
// set on installed and assign another one
|
||||
deploymentManagement.assignDistributionSet(installedSet, installedtargets).getActions().forEach(actionId -> {
|
||||
|
||||
@@ -43,6 +43,8 @@ import org.eclipse.hawkbit.repository.model.Tag;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.model.TargetIdName;
|
||||
import org.eclipse.hawkbit.repository.model.TargetTag;
|
||||
import org.eclipse.hawkbit.repository.util.WithSpringAuthorityRule;
|
||||
import org.eclipse.hawkbit.repository.util.WithUser;
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
|
||||
@@ -54,7 +56,7 @@ import ru.yandex.qatools.allure.annotations.Stories;
|
||||
|
||||
@Features("Component Tests - Repository")
|
||||
@Stories("Target Management")
|
||||
public class TargetManagementTest extends AbstractIntegrationTest {
|
||||
public class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
@Test
|
||||
@Description("Ensures that retrieving the target security is only permitted with the necessary permissions.")
|
||||
@@ -193,10 +195,8 @@ public class TargetManagementTest extends AbstractIntegrationTest {
|
||||
@Test
|
||||
@Description("Finds a target by given ID and checks if all data is in the reponse (including the data defined as lazy).")
|
||||
public void findTargetByControllerIDWithDetails() {
|
||||
final DistributionSet set = TestDataUtil.generateDistributionSet("test", softwareManagement,
|
||||
distributionSetManagement);
|
||||
final DistributionSet set2 = TestDataUtil.generateDistributionSet("test2", softwareManagement,
|
||||
distributionSetManagement);
|
||||
final DistributionSet set = testdataFactory.createDistributionSet("test");
|
||||
final DistributionSet set2 = testdataFactory.createDistributionSet("test2");
|
||||
|
||||
assertThat(targetManagement.countTargetByAssignedDistributionSet(set.getId())).as("Target count is wrong")
|
||||
.isEqualTo(0);
|
||||
@@ -248,7 +248,7 @@ public class TargetManagementTest extends AbstractIntegrationTest {
|
||||
@Test
|
||||
@Description("Checks if the EntityAlreadyExistsException is thrown if the targets with the same controller ID are created twice.")
|
||||
public void createMultipleTargetsDuplicate() {
|
||||
final List<Target> targets = TestDataUtil.buildTargetFixtures(5, "mySimpleTargs", "my simple targets");
|
||||
final List<Target> targets = testdataFactory.generateTargets(5, "mySimpleTargs", "my simple targets");
|
||||
targetManagement.createTargets(targets);
|
||||
try {
|
||||
targetManagement.createTargets(targets);
|
||||
@@ -323,7 +323,7 @@ public class TargetManagementTest extends AbstractIntegrationTest {
|
||||
public void singleTargetIsInsertedIntoRepo() throws Exception {
|
||||
|
||||
final String myCtrlID = "myCtrlID";
|
||||
final Target target = TestDataUtil.buildTargetFixture(myCtrlID, "the description!");
|
||||
final Target target = testdataFactory.generateTarget(myCtrlID, "the description!");
|
||||
|
||||
Target savedTarget = targetManagement.createTarget(target);
|
||||
assertNotNull("The target should not be null", savedTarget);
|
||||
@@ -360,9 +360,9 @@ public class TargetManagementTest extends AbstractIntegrationTest {
|
||||
@Description("Create multiple tragets as bulk operation and delete them in bulk.")
|
||||
public void bulkTargetCreationAndDelete() throws Exception {
|
||||
final String myCtrlID = "myCtrlID";
|
||||
final List<Target> firstList = TestDataUtil.buildTargetFixtures(100, myCtrlID, "first description");
|
||||
final List<Target> firstList = testdataFactory.generateTargets(100, myCtrlID, "first description");
|
||||
|
||||
final Target extra = TestDataUtil.buildTargetFixture("myCtrlID-00081XX", "first description");
|
||||
final Target extra = testdataFactory.generateTarget("myCtrlID-00081XX", "first description");
|
||||
|
||||
List<Target> firstSaved = targetManagement.createTargets(firstList);
|
||||
|
||||
@@ -432,7 +432,7 @@ public class TargetManagementTest extends AbstractIntegrationTest {
|
||||
@Description("Stores target attributes and verfies existence in the repository.")
|
||||
public void savingTargetControllerAttributes() {
|
||||
Iterable<Target> ts = targetManagement
|
||||
.createTargets(TestDataUtil.buildTargetFixtures(100, "myCtrlID", "first description"));
|
||||
.createTargets(testdataFactory.generateTargets(100, "myCtrlID", "first description"));
|
||||
|
||||
final Map<String, String> attribs = new HashMap<>();
|
||||
attribs.put("a.b.c", "abc");
|
||||
@@ -541,17 +541,17 @@ public class TargetManagementTest extends AbstractIntegrationTest {
|
||||
@Test
|
||||
@Description("Tests the assigment of tags to the a single target.")
|
||||
public void targetTagAssignment() {
|
||||
Target t1 = TestDataUtil.buildTargetFixture("id-1", "blablub");
|
||||
Target t1 = testdataFactory.generateTarget("id-1", "blablub");
|
||||
final int noT2Tags = 4;
|
||||
final int noT1Tags = 3;
|
||||
final List<TargetTag> t1Tags = tagManagement
|
||||
.createTargetTags(TestDataUtil.buildTargetTagFixtures(noT1Tags, "tag1"));
|
||||
.createTargetTags(testdataFactory.generateTargetTags(noT1Tags, "tag1"));
|
||||
t1.getTags().addAll(t1Tags);
|
||||
t1 = targetManagement.createTarget(t1);
|
||||
|
||||
Target t2 = TestDataUtil.buildTargetFixture("id-2", "blablub");
|
||||
Target t2 = testdataFactory.generateTarget("id-2", "blablub");
|
||||
final List<TargetTag> t2Tags = tagManagement
|
||||
.createTargetTags(TestDataUtil.buildTargetTagFixtures(noT2Tags, "tag2"));
|
||||
.createTargetTags(testdataFactory.generateTargetTags(noT2Tags, "tag2"));
|
||||
t2.getTags().addAll(t2Tags);
|
||||
t2 = targetManagement.createTarget(t2);
|
||||
|
||||
@@ -570,17 +570,17 @@ public class TargetManagementTest extends AbstractIntegrationTest {
|
||||
@Description("Tests the assigment of tags to multiple targets.")
|
||||
public void targetTagBulkAssignments() {
|
||||
final List<Target> tagATargets = targetManagement
|
||||
.createTargets(TestDataUtil.buildTargetFixtures(10, "tagATargets", "first description"));
|
||||
.createTargets(testdataFactory.generateTargets(10, "tagATargets", "first description"));
|
||||
final List<Target> tagBTargets = targetManagement
|
||||
.createTargets(TestDataUtil.buildTargetFixtures(10, "tagBTargets", "first description"));
|
||||
.createTargets(testdataFactory.generateTargets(10, "tagBTargets", "first description"));
|
||||
final List<Target> tagCTargets = targetManagement
|
||||
.createTargets(TestDataUtil.buildTargetFixtures(10, "tagCTargets", "first description"));
|
||||
.createTargets(testdataFactory.generateTargets(10, "tagCTargets", "first description"));
|
||||
|
||||
final List<Target> tagABTargets = targetManagement
|
||||
.createTargets(TestDataUtil.buildTargetFixtures(10, "tagABTargets", "first description"));
|
||||
.createTargets(testdataFactory.generateTargets(10, "tagABTargets", "first description"));
|
||||
|
||||
final List<Target> tagABCTargets = targetManagement
|
||||
.createTargets(TestDataUtil.buildTargetFixtures(10, "tagABCTargets", "first description"));
|
||||
.createTargets(testdataFactory.generateTargets(10, "tagABCTargets", "first description"));
|
||||
|
||||
final TargetTag tagA = tagManagement.createTargetTag(new JpaTargetTag("A"));
|
||||
final TargetTag tagB = tagManagement.createTargetTag(new JpaTargetTag("B"));
|
||||
@@ -645,20 +645,20 @@ public class TargetManagementTest extends AbstractIntegrationTest {
|
||||
final TargetTag targTagC = tagManagement.createTargetTag(new JpaTargetTag("Targ-C-Tag"));
|
||||
|
||||
final List<Target> targAs = targetManagement
|
||||
.createTargets(TestDataUtil.buildTargetFixtures(25, "target-id-A", "first description"));
|
||||
.createTargets(testdataFactory.generateTargets(25, "target-id-A", "first description"));
|
||||
final List<Target> targBs = targetManagement
|
||||
.createTargets(TestDataUtil.buildTargetFixtures(20, "target-id-B", "first description"));
|
||||
.createTargets(testdataFactory.generateTargets(20, "target-id-B", "first description"));
|
||||
final List<Target> targCs = targetManagement
|
||||
.createTargets(TestDataUtil.buildTargetFixtures(15, "target-id-C", "first description"));
|
||||
.createTargets(testdataFactory.generateTargets(15, "target-id-C", "first description"));
|
||||
|
||||
final List<Target> targABs = targetManagement
|
||||
.createTargets(TestDataUtil.buildTargetFixtures(12, "target-id-AB", "first description"));
|
||||
.createTargets(testdataFactory.generateTargets(12, "target-id-AB", "first description"));
|
||||
final List<Target> targACs = targetManagement
|
||||
.createTargets(TestDataUtil.buildTargetFixtures(13, "target-id-AC", "first description"));
|
||||
.createTargets(testdataFactory.generateTargets(13, "target-id-AC", "first description"));
|
||||
final List<Target> targBCs = targetManagement
|
||||
.createTargets(TestDataUtil.buildTargetFixtures(7, "target-id-BC", "first description"));
|
||||
.createTargets(testdataFactory.generateTargets(7, "target-id-BC", "first description"));
|
||||
final List<Target> targABCs = targetManagement
|
||||
.createTargets(TestDataUtil.buildTargetFixtures(17, "target-id-ABC", "first description"));
|
||||
.createTargets(testdataFactory.generateTargets(17, "target-id-ABC", "first description"));
|
||||
|
||||
targetManagement.toggleTagAssignment(targAs, targTagA);
|
||||
targetManagement.toggleTagAssignment(targABs, targTagA);
|
||||
@@ -706,7 +706,7 @@ public class TargetManagementTest extends AbstractIntegrationTest {
|
||||
final TargetTag targTagA = tagManagement.createTargetTag(new JpaTargetTag("Targ-A-Tag"));
|
||||
|
||||
final List<Target> targAs = targetManagement
|
||||
.createTargets(TestDataUtil.buildTargetFixtures(25, "target-id-A", "first description"));
|
||||
.createTargets(testdataFactory.generateTargets(25, "target-id-A", "first description"));
|
||||
|
||||
targetManagement.toggleTagAssignment(targAs, targTagA);
|
||||
|
||||
@@ -726,7 +726,7 @@ public class TargetManagementTest extends AbstractIntegrationTest {
|
||||
@Description("Test the optimized quere for retrieving all ID/name pairs of targets.")
|
||||
public void findAllTargetIdNamePaiss() {
|
||||
final List<Target> targAs = targetManagement
|
||||
.createTargets(TestDataUtil.buildTargetFixtures(25, "target-id-A", "first description"));
|
||||
.createTargets(testdataFactory.generateTargets(25, "target-id-A", "first description"));
|
||||
final String[] createdTargetIds = targAs.stream().map(t -> t.getControllerId())
|
||||
.toArray(size -> new String[size]);
|
||||
|
||||
@@ -743,10 +743,10 @@ public class TargetManagementTest extends AbstractIntegrationTest {
|
||||
|
||||
final TargetTag targTagA = tagManagement.createTargetTag(new JpaTargetTag("Targ-A-Tag"));
|
||||
final List<Target> targAs = targetManagement
|
||||
.createTargets(TestDataUtil.buildTargetFixtures(25, "target-id-A", "first description"));
|
||||
.createTargets(testdataFactory.generateTargets(25, "target-id-A", "first description"));
|
||||
targetManagement.toggleTagAssignment(targAs, targTagA);
|
||||
|
||||
targetManagement.createTargets(TestDataUtil.buildTargetFixtures(25, "target-id-B", "first description"));
|
||||
targetManagement.createTargets(testdataFactory.generateTargets(25, "target-id-B", "first description"));
|
||||
|
||||
final String[] tagNames = null;
|
||||
final List<Target> targetsListWithNoTag = targetManagement
|
||||
|
||||
@@ -29,7 +29,7 @@ import ru.yandex.qatools.allure.annotations.Stories;
|
||||
|
||||
@Features("Component Tests - Repository")
|
||||
@Stories("Tenant Configuration Management")
|
||||
public class TenantConfigurationManagementTest extends AbstractIntegrationTestWithMongoDB {
|
||||
public class TenantConfigurationManagementTest extends AbstractJpaIntegrationTestWithMongoDB {
|
||||
|
||||
@Test
|
||||
@Description("Tests that tenant specific configuration can be persisted and in case the tenant does not have specific configuration the default from environment is used instead.")
|
||||
|
||||
@@ -16,8 +16,8 @@ import org.eclipse.hawkbit.cache.CacheConstants;
|
||||
import org.eclipse.hawkbit.cache.TenancyCacheManager;
|
||||
import org.eclipse.hawkbit.cache.TenantAwareCacheManager;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.helper.EventBusHolder;
|
||||
import org.eclipse.hawkbit.repository.jpa.utils.RepositoryDataGenerator;
|
||||
import org.eclipse.hawkbit.repository.jpa.utils.RepositoryDataGenerator.DatabaseCleanupUtil;
|
||||
import org.eclipse.hawkbit.repository.util.TestRepositoryManagement;
|
||||
import org.eclipse.hawkbit.repository.util.TestdataFactory;
|
||||
import org.eclipse.hawkbit.security.DdiSecurityProperties;
|
||||
import org.eclipse.hawkbit.security.SecurityContextTenantAware;
|
||||
import org.eclipse.hawkbit.security.SpringSecurityAuditorAware;
|
||||
@@ -52,14 +52,14 @@ import com.mongodb.MongoClientOptions;
|
||||
@Profile("test")
|
||||
public class TestConfiguration implements AsyncConfigurer {
|
||||
|
||||
/**
|
||||
* DB cleanup utility bean is created.
|
||||
*
|
||||
* @return the {@link DatabaseCleanupUtil} bean
|
||||
*/
|
||||
@Bean
|
||||
public DatabaseCleanupUtil createDatabaseCleanupUtil() {
|
||||
return new RepositoryDataGenerator.DatabaseCleanupUtil();
|
||||
public TestRepositoryManagement testRepositoryManagement() {
|
||||
return new JpaTestRepositoryManagement();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public TestdataFactory testdataFactory() {
|
||||
return new TestdataFactory();
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -1,435 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.eclipse.hawkbit.repository.ArtifactManagement;
|
||||
import org.eclipse.hawkbit.repository.ControllerManagement;
|
||||
import org.eclipse.hawkbit.repository.DistributionSetManagement;
|
||||
import org.eclipse.hawkbit.repository.SoftwareManagement;
|
||||
import org.eclipse.hawkbit.repository.TargetManagement;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.AbstractJpaArtifact;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetTag;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetType;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleType;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag;
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.Action.Status;
|
||||
import org.eclipse.hawkbit.repository.model.ActionStatus;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetTag;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetType;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.model.TargetTag;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import net._01001111.text.LoremIpsum;
|
||||
|
||||
/**
|
||||
* Data generator utility for tests.
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class TestDataUtil {
|
||||
private static final LoremIpsum LOREM = new LoremIpsum();
|
||||
|
||||
public static DistributionSet createTestDistributionSet(final SoftwareManagement softwareManagement,
|
||||
final DistributionSetManagement distributionSetManagement) {
|
||||
final Pageable pageReq = new PageRequest(0, 400);
|
||||
DistributionSet set = TestDataUtil.generateDistributionSet("one", softwareManagement,
|
||||
distributionSetManagement);
|
||||
set.setVersion("anotherVersion");
|
||||
set = distributionSetManagement.updateDistributionSet(set);
|
||||
|
||||
set.getModules().forEach(module -> {
|
||||
module.setDescription("updated description");
|
||||
softwareManagement.updateSoftwareModule(module);
|
||||
});
|
||||
|
||||
// load also lazy stuff
|
||||
set = distributionSetManagement.findDistributionSetByIdWithDetails(set.getId());
|
||||
|
||||
assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(pageReq, false, true)).hasSize(1);
|
||||
return set;
|
||||
}
|
||||
|
||||
public static List<Target> sendUpdateActionStatusToTargets(final ControllerManagement controllerManagament,
|
||||
final TargetManagement targetManagement, final ActionRepository actionRepository, final DistributionSet dsA,
|
||||
final Iterable<Target> targs, final Status status, final String... msgs) {
|
||||
final List<Target> result = new ArrayList<>();
|
||||
for (final Target t : targs) {
|
||||
final List<Action> findByTarget = actionRepository.findByTarget((JpaTarget) t);
|
||||
for (final Action action : findByTarget) {
|
||||
result.add(sendUpdateActionStatusToTarget(controllerManagament, targetManagement, status, action, t,
|
||||
msgs));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static Target sendUpdateActionStatusToTarget(final ControllerManagement controllerManagament,
|
||||
final TargetManagement targetManagement, final Status status, final Action updActA, final Target t,
|
||||
final String... msgs) {
|
||||
updActA.setStatus(status);
|
||||
|
||||
final ActionStatus statusMessages = new JpaActionStatus();
|
||||
statusMessages.setAction(updActA);
|
||||
statusMessages.setOccurredAt(System.currentTimeMillis());
|
||||
statusMessages.setStatus(status);
|
||||
for (final String msg : msgs) {
|
||||
statusMessages.addMessage(msg);
|
||||
}
|
||||
controllerManagament.addUpdateActionStatus(statusMessages);
|
||||
return targetManagement.findTargetByControllerID(t.getControllerId());
|
||||
}
|
||||
|
||||
public static List<JpaDistributionSet> generateDistributionSets(final String suffix, final int number,
|
||||
final SoftwareManagement softwareManagement, final DistributionSetManagement distributionSetManagement) {
|
||||
|
||||
final List<JpaDistributionSet> sets = new ArrayList<>();
|
||||
for (int i = 0; i < number; i++) {
|
||||
sets.add(generateDistributionSet(suffix, "v1." + i, softwareManagement, distributionSetManagement, false));
|
||||
}
|
||||
|
||||
return sets;
|
||||
}
|
||||
|
||||
public static DistributionSet generateDistributionSetWithNoSoftwareModules(final String name, final String version,
|
||||
final DistributionSetManagement distributionSetManagement) {
|
||||
|
||||
final DistributionSet dis = new JpaDistributionSet();
|
||||
dis.setName(name);
|
||||
dis.setVersion(version);
|
||||
dis.setDescription("Test describtion for " + name);
|
||||
return distributionSetManagement.createDistributionSet(dis);
|
||||
}
|
||||
|
||||
public static List<JpaDistributionSet> generateDistributionSets(final int number,
|
||||
final SoftwareManagement softwareManagement, final DistributionSetManagement distributionSetManagement) {
|
||||
|
||||
return generateDistributionSets("", number, softwareManagement, distributionSetManagement);
|
||||
}
|
||||
|
||||
public static JpaDistributionSet generateDistributionSet(final String suffix, final String version,
|
||||
final SoftwareManagement softwareManagement, final DistributionSetManagement distributionSetManagement,
|
||||
final boolean isRequiredMigrationStep) {
|
||||
|
||||
final SoftwareModule ah = softwareManagement.createSoftwareModule(new JpaSoftwareModule(
|
||||
findOrCreateSoftwareModuleType(softwareManagement, "application"), suffix + "application",
|
||||
version + "." + new Random().nextInt(100), LOREM.words(20), suffix + " vendor Limited, California"));
|
||||
final SoftwareModule jvm = softwareManagement.createSoftwareModule(
|
||||
new JpaSoftwareModule(findOrCreateSoftwareModuleType(softwareManagement, "runtime"),
|
||||
suffix + "app runtime", version + "." + new Random().nextInt(100), LOREM.words(20),
|
||||
suffix + " vendor GmbH, Stuttgart, Germany"));
|
||||
final SoftwareModule os = softwareManagement
|
||||
.createSoftwareModule(new JpaSoftwareModule(findOrCreateSoftwareModuleType(softwareManagement, "os"),
|
||||
suffix + " Firmware", version + "." + new Random().nextInt(100), LOREM.words(20),
|
||||
suffix + " vendor Limited Inc, California"));
|
||||
|
||||
final List<SoftwareModuleType> mand = new ArrayList<>();
|
||||
mand.add(findOrCreateSoftwareModuleType(softwareManagement, "os"));
|
||||
|
||||
final List<SoftwareModuleType> opt = new ArrayList<>();
|
||||
opt.add(findOrCreateSoftwareModuleType(softwareManagement, "application"));
|
||||
opt.add(findOrCreateSoftwareModuleType(softwareManagement, "runtime"));
|
||||
|
||||
return (JpaDistributionSet) distributionSetManagement.createDistributionSet(
|
||||
buildDistributionSet(suffix != null && suffix.length() > 0 ? suffix : "DS", version,
|
||||
findOrCreateDistributionSetType(distributionSetManagement, "ecl_os_app_jvm",
|
||||
"OS mandatory App/JVM optional", mand, opt),
|
||||
os, jvm, ah).setRequiredMigrationStep(isRequiredMigrationStep));
|
||||
}
|
||||
|
||||
public static DistributionSet generateDistributionSet(final String suffix, final String version,
|
||||
final SoftwareManagement softwareManagement, final DistributionSetManagement distributionSetManagement,
|
||||
final Collection<DistributionSetTag> tags) {
|
||||
|
||||
final DistributionSet set = generateDistributionSet(suffix, version, softwareManagement,
|
||||
distributionSetManagement, false);
|
||||
|
||||
final List<DistributionSet> sets = new ArrayList<DistributionSet>();
|
||||
sets.add(set);
|
||||
|
||||
tags.forEach(tag -> distributionSetManagement.toggleTagAssignment(sets, tag));
|
||||
|
||||
return distributionSetManagement.findDistributionSetById(set.getId());
|
||||
|
||||
}
|
||||
|
||||
public static List<Target> generateTargets(final int number) {
|
||||
return generateTargets(0, number, "Test target ");
|
||||
}
|
||||
|
||||
public static List<Target> generateTargets(final int number, final String prefix) {
|
||||
return generateTargets(0, number, prefix);
|
||||
}
|
||||
|
||||
public static List<Target> generateTargets(final int start, final int number, final String prefix) {
|
||||
final List<Target> targets = new ArrayList<>();
|
||||
for (int i = start; i < start + number; i++) {
|
||||
targets.add(new JpaTarget(prefix + i));
|
||||
}
|
||||
|
||||
return targets;
|
||||
}
|
||||
|
||||
public static List<TargetTag> generateTargetTags(final int number) {
|
||||
final List<TargetTag> result = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i < number; i++) {
|
||||
result.add(new JpaTargetTag("tag" + i, "tagdesc" + i, "" + i));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static List<DistributionSetTag> generateDistributionSetTags(final int number) {
|
||||
final List<DistributionSetTag> result = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i < number; i++) {
|
||||
result.add(new JpaDistributionSetTag("tag" + i, "tagdesc" + i, "" + i));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static JpaDistributionSet generateDistributionSet(final String suffix,
|
||||
final SoftwareManagement softwareManagement, final DistributionSetManagement distributionSetManagement,
|
||||
final boolean isRequiredMigrationStep) {
|
||||
return generateDistributionSet(suffix, "v1.0", softwareManagement, distributionSetManagement,
|
||||
isRequiredMigrationStep);
|
||||
}
|
||||
|
||||
public static JpaDistributionSet generateDistributionSet(final String suffix,
|
||||
final SoftwareManagement softwareManagement, final DistributionSetManagement distributionSetManagement) {
|
||||
return generateDistributionSet(suffix, "v1.0", softwareManagement, distributionSetManagement, false);
|
||||
}
|
||||
|
||||
public static List<AbstractJpaArtifact> generateArtifacts(final ArtifactManagement artifactManagement,
|
||||
final Long moduleId) {
|
||||
final List<AbstractJpaArtifact> artifacts = new ArrayList<>();
|
||||
for (int i = 0; i < 3; i++) {
|
||||
final InputStream stubInputStream = IOUtils.toInputStream("some test data" + i);
|
||||
artifacts.add((AbstractJpaArtifact) artifactManagement.createLocalArtifact(stubInputStream, moduleId,
|
||||
"filename" + i, false));
|
||||
|
||||
}
|
||||
|
||||
return artifacts;
|
||||
}
|
||||
|
||||
public static Target createTarget(final TargetManagement targetManagement) {
|
||||
final String targetExist = "targetExist";
|
||||
final Target target = new JpaTarget(targetExist);
|
||||
targetManagement.createTarget(target);
|
||||
return target;
|
||||
}
|
||||
|
||||
public static DistributionSet generateDistributionSet(final String suffix,
|
||||
final SoftwareManagement softwareManagement, final DistributionSetManagement distributionSetManagement,
|
||||
final Collection<DistributionSetTag> tags) {
|
||||
return generateDistributionSet(suffix, "v1.0", softwareManagement, distributionSetManagement, tags);
|
||||
}
|
||||
|
||||
public static SoftwareModuleType findOrCreateSoftwareModuleType(final SoftwareManagement softwareManagement,
|
||||
final String softwareModuleType) {
|
||||
final SoftwareModuleType findSoftwareModuleTypeByKey = softwareManagement
|
||||
.findSoftwareModuleTypeByKey(softwareModuleType);
|
||||
if (findSoftwareModuleTypeByKey != null) {
|
||||
return findSoftwareModuleTypeByKey;
|
||||
}
|
||||
return softwareManagement.createSoftwareModuleType(new JpaSoftwareModuleType(softwareModuleType,
|
||||
softwareModuleType, "Standard type " + softwareManagement, 1));
|
||||
}
|
||||
|
||||
public static DistributionSetType findOrCreateDistributionSetType(
|
||||
final DistributionSetManagement distributionSetManagement, final String dsTypeKey, final String dsTypeName,
|
||||
final Collection<SoftwareModuleType> mandatory, final Collection<SoftwareModuleType> optional) {
|
||||
final DistributionSetType findDistributionSetTypeByname = distributionSetManagement
|
||||
.findDistributionSetTypeByKey(dsTypeKey);
|
||||
|
||||
if (findDistributionSetTypeByname != null) {
|
||||
return findDistributionSetTypeByname;
|
||||
}
|
||||
|
||||
final DistributionSetType type = new JpaDistributionSetType(dsTypeKey, dsTypeName,
|
||||
"Standard type" + dsTypeName);
|
||||
mandatory.forEach(entry -> type.addMandatoryModuleType(entry));
|
||||
optional.forEach(entry -> type.addOptionalModuleType(entry));
|
||||
|
||||
return distributionSetManagement.createDistributionSetType(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* builds a set of {@link Target} fixtures from the given parameters.
|
||||
*
|
||||
* @param noOfTgts
|
||||
* number of targets to create
|
||||
* @param ctlrIDPrefix
|
||||
* prefix used for the controller ID
|
||||
* @param descriptionPrefix
|
||||
* prefix used for the description
|
||||
* @return set of {@link Target}
|
||||
*/
|
||||
public static List<Target> buildTargetFixtures(final int noOfTgts, final String ctlrIDPrefix,
|
||||
final String descriptionPrefix) {
|
||||
return buildTargetFixtures(noOfTgts, ctlrIDPrefix, descriptionPrefix, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* method creates set of targets by by generating the controller ID and the
|
||||
* description like: prefix + no of target.
|
||||
*
|
||||
* @param noOfTgts
|
||||
* number of targets which should be created
|
||||
* @param ctlrIDPrefix
|
||||
* prefix of the controllerID which is concatenated with the
|
||||
* number of the target
|
||||
* @param descriptionPrefix
|
||||
* prefix of the target description which is concatenated with
|
||||
* the number of the target
|
||||
* @param tags
|
||||
* tags which should be added to the created {@link Target}s
|
||||
* @return set of created targets
|
||||
*/
|
||||
public static List<Target> buildTargetFixtures(final int noOfTgts, final String ctlrIDPrefix,
|
||||
final String descriptionPrefix, final TargetTag[] tags) {
|
||||
final List<Target> list = new ArrayList<Target>();
|
||||
for (int i = 0; i < noOfTgts; i++) {
|
||||
String ctrlID = ctlrIDPrefix;
|
||||
if (Strings.isNullOrEmpty(ctrlID)) {
|
||||
ctrlID = UUID.randomUUID().toString();
|
||||
}
|
||||
ctrlID = String.format("%s-%05d", ctrlID, i);
|
||||
|
||||
final String description = String.format("the description of ProvisioningTarget: [%s]", ctrlID);
|
||||
|
||||
final Target target = buildTargetFixture(ctrlID, description, tags);
|
||||
list.add(target);
|
||||
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* builds a single {@link Target} fixture from the given parameters.
|
||||
*
|
||||
* @param ctrlID
|
||||
* controllerID
|
||||
* @param description
|
||||
* the description of the target
|
||||
* @param tags
|
||||
* assigned {@link TargetTag}s
|
||||
* @return the created {@link Target}
|
||||
*/
|
||||
public static Target buildTargetFixture(final String ctrlID, final String description, final TargetTag[] tags) {
|
||||
final Target target = new JpaTarget(ctrlID);
|
||||
target.setName("Prov.Target ".concat(ctrlID));
|
||||
target.setDescription(description);
|
||||
if (tags != null && tags.length > 0) {
|
||||
for (final TargetTag t : tags) {
|
||||
target.getTags().add(t);
|
||||
}
|
||||
}
|
||||
return target;
|
||||
}
|
||||
|
||||
/**
|
||||
* builder method for creating a single target object.
|
||||
*
|
||||
* @param ctrlID
|
||||
* the ID of the target
|
||||
* @param description
|
||||
* of the target
|
||||
* @return the created target object
|
||||
*/
|
||||
public static Target buildTargetFixture(final String ctrlID, final String description) {
|
||||
return buildTargetFixture(ctrlID, description, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* builder method for creating a {@link DistributionSet}.
|
||||
*
|
||||
* @param name
|
||||
* of the DS
|
||||
* @param version
|
||||
* of the DS
|
||||
* @param os
|
||||
* operating system of the DS
|
||||
* @param jvm
|
||||
* java virtual machine of the DS
|
||||
* @param agentHub
|
||||
* of the DS
|
||||
* @return the created {@link DistributionSet}
|
||||
*/
|
||||
public static DistributionSet buildDistributionSet(final String name, final String version,
|
||||
final DistributionSetType type, final SoftwareModule os, final SoftwareModule jvm,
|
||||
final SoftwareModule agentHub) {
|
||||
final DistributionSet distributionSet = new JpaDistributionSet(name, version, null, type,
|
||||
Lists.newArrayList(os, jvm, agentHub));
|
||||
distributionSet.setDescription(
|
||||
String.format("description of DistributionSet; name = '%s', version = '%s'", name, version));
|
||||
return distributionSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* builder method for creating a set of {@link TargetTag}.
|
||||
*
|
||||
* @param noOfTags
|
||||
* number of {@link TargetTag}. to be created
|
||||
* @param tagPrefix
|
||||
* prefix for the {@link TargetTag.getName()}
|
||||
* @return the created set of {@link TargetTag}s
|
||||
*/
|
||||
public static List<TargetTag> buildTargetTagFixtures(final int noOfTags, final String tagPrefix) {
|
||||
final List<TargetTag> list = new ArrayList<>();
|
||||
for (int i = 0; i < noOfTags; i++) {
|
||||
String tagName = "myTag";
|
||||
if (!Strings.isNullOrEmpty(tagPrefix)) {
|
||||
tagName = tagPrefix;
|
||||
}
|
||||
tagName = String.format("%s-%05d", tagName, i);
|
||||
|
||||
final TargetTag targetTag = buildTargetTagFixture(tagName);
|
||||
list.add(targetTag);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* builder method for creating a simple {@link TargetTag}.
|
||||
*
|
||||
* @param tagName
|
||||
* name of the Tag
|
||||
* @return the {@link TargetTag}
|
||||
*/
|
||||
public static TargetTag buildTargetTagFixture(final String tagName) {
|
||||
return new JpaTargetTag(tagName);
|
||||
}
|
||||
}
|
||||
@@ -1,278 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import org.eclipse.hawkbit.im.authentication.SpPermission;
|
||||
import org.eclipse.hawkbit.im.authentication.TenantAwareAuthenticationDetails;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.helper.SystemManagementHolder;
|
||||
import org.junit.rules.TestRule;
|
||||
import org.junit.runner.Description;
|
||||
import org.junit.runners.model.Statement;
|
||||
import org.springframework.security.authentication.TestingAuthenticationToken;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.context.SecurityContext;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
|
||||
public class WithSpringAuthorityRule implements TestRule {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.junit.rules.TestRule#apply(org.junit.runners.model.Statement,
|
||||
* org.junit.runner.Description)
|
||||
*/
|
||||
@Override
|
||||
public Statement apply(final Statement base, final Description description) {
|
||||
return new Statement() {
|
||||
@Override
|
||||
public void evaluate() throws Throwable {
|
||||
final SecurityContext oldContext = before(description);
|
||||
try {
|
||||
base.evaluate();
|
||||
} finally {
|
||||
after(oldContext);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private SecurityContext before(final Description description) throws Throwable {
|
||||
final SecurityContext oldContext = SecurityContextHolder.getContext();
|
||||
WithUser annotation = description.getAnnotation(WithUser.class);
|
||||
if (annotation == null) {
|
||||
annotation = description.getTestClass().getAnnotation(WithUser.class);
|
||||
}
|
||||
if (annotation != null) {
|
||||
setSecurityContext(annotation);
|
||||
if (annotation.autoCreateTenant()) {
|
||||
SystemManagementHolder.getInstance().getSystemManagement().getTenantMetadata(annotation.tenantId());
|
||||
}
|
||||
}
|
||||
return oldContext;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param annotation
|
||||
*/
|
||||
private void setSecurityContext(final WithUser annotation) {
|
||||
SecurityContextHolder.setContext(new SecurityContext() {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
public void setAuthentication(final Authentication authentication) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Authentication getAuthentication() {
|
||||
final String[] authorities;
|
||||
if (annotation.allSpPermissions()) {
|
||||
authorities = getAllAuthorities(annotation.authorities(), annotation.removeFromAllPermission());
|
||||
} else {
|
||||
authorities = annotation.authorities();
|
||||
}
|
||||
final TestingAuthenticationToken testingAuthenticationToken = new TestingAuthenticationToken(
|
||||
annotation.principal(), annotation.credentials(), authorities);
|
||||
testingAuthenticationToken
|
||||
.setDetails(new TenantAwareAuthenticationDetails(annotation.tenantId(), false));
|
||||
return testingAuthenticationToken;
|
||||
}
|
||||
|
||||
private String[] getAllAuthorities(final String[] additionalAuthorities, final String[] notInclude) {
|
||||
final List<String> allPermissions = new ArrayList<>();
|
||||
final Field[] declaredFields = SpPermission.class.getDeclaredFields();
|
||||
for (final Field field : declaredFields) {
|
||||
if (Modifier.isPublic(field.getModifiers()) && Modifier.isStatic(field.getModifiers())) {
|
||||
field.setAccessible(true);
|
||||
try {
|
||||
boolean addPermission = true;
|
||||
final String permissionName = (String) field.get(null);
|
||||
if (notInclude != null) {
|
||||
for (final String notInlcudePerm : notInclude) {
|
||||
if (permissionName.equals(notInlcudePerm)) {
|
||||
addPermission = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (addPermission) {
|
||||
allPermissions.add(permissionName);
|
||||
}
|
||||
} catch (IllegalArgumentException | IllegalAccessException e) {
|
||||
// nope
|
||||
}
|
||||
}
|
||||
}
|
||||
for (final String authority : additionalAuthorities) {
|
||||
allPermissions.add(authority);
|
||||
}
|
||||
return allPermissions.toArray(new String[allPermissions.size()]);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void after(final SecurityContext oldContext) {
|
||||
SecurityContextHolder.setContext(oldContext);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param callable
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public <T> T runAsPrivileged(final Callable<T> callable) throws Exception {
|
||||
return runAs(privilegedUser(), callable);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param withUser
|
||||
* @param callable
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public <T> T runAs(final WithUser withUser, final Callable<T> callable) throws Exception {
|
||||
final SecurityContext oldContext = SecurityContextHolder.getContext();
|
||||
setSecurityContext(withUser);
|
||||
if (withUser.autoCreateTenant()) {
|
||||
SystemManagementHolder.getInstance().getSystemManagement().getTenantMetadata(withUser.tenantId());
|
||||
}
|
||||
try {
|
||||
return callable.call();
|
||||
} finally {
|
||||
after(oldContext);
|
||||
}
|
||||
}
|
||||
|
||||
public static WithUser withUser(final String principal, final String... authorities) {
|
||||
return withUserAndTenant(principal, "default", true, true, authorities);
|
||||
}
|
||||
|
||||
public static WithUser withUser(final String principal, final boolean allSpPermision, final String... authorities) {
|
||||
return withUserAndTenant(principal, "default", true, allSpPermision, authorities);
|
||||
}
|
||||
|
||||
public static WithUser withUser(final boolean autoCreateTenant) {
|
||||
return withUserAndTenant("bumlux", "default", autoCreateTenant, true, new String[] {});
|
||||
}
|
||||
|
||||
public static WithUser withUserAndTenant(final String principal, final String tenant, final String... authorities) {
|
||||
return withUserAndTenant(principal, tenant, true, true, new String[] {});
|
||||
}
|
||||
|
||||
public static WithUser withUserAndTenant(final String principal, final String tenant,
|
||||
final boolean autoCreateTenant, final boolean allSpPermission, final String... authorities) {
|
||||
return new WithUser() {
|
||||
|
||||
@Override
|
||||
public Class<? extends Annotation> annotationType() {
|
||||
return WithUser.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String principal() {
|
||||
return principal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String credentials() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] authorities() {
|
||||
return authorities;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean allSpPermissions() {
|
||||
return allSpPermission;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] removeFromAllPermission() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String tenantId() {
|
||||
return tenant;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.hawkbit.WithUser#autoCreateTenant()
|
||||
*/
|
||||
@Override
|
||||
public boolean autoCreateTenant() {
|
||||
return autoCreateTenant;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static WithUser privilegedUser() {
|
||||
return new WithUser() {
|
||||
|
||||
@Override
|
||||
public Class<? extends Annotation> annotationType() {
|
||||
return WithUser.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String principal() {
|
||||
return "bumlux";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String credentials() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] authorities() {
|
||||
return new String[] { "ROLE_CONTROLLER" };
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean allSpPermissions() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] removeFromAllPermission() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String tenantId() {
|
||||
return "default";
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.hawkbit.WithUser#autoCreateTenant()
|
||||
*/
|
||||
@Override
|
||||
public boolean autoCreateTenant() {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Inherited;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Annotation to run test classes or test methods with a specific user with
|
||||
* specific permissions.
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ ElementType.METHOD, ElementType.TYPE })
|
||||
@Inherited
|
||||
public @interface WithUser {
|
||||
|
||||
/**
|
||||
* Gets the test principal.
|
||||
*
|
||||
* @return test principal
|
||||
*/
|
||||
String principal() default "TestPrincipal";
|
||||
|
||||
/**
|
||||
* Gets the test credentials.
|
||||
*
|
||||
* @return test credentials
|
||||
*/
|
||||
String credentials() default "TestCredentials";
|
||||
|
||||
/**
|
||||
* Gets the test tenant id.
|
||||
*
|
||||
* @return test tenant id
|
||||
*/
|
||||
String tenantId() default "default";
|
||||
|
||||
/**
|
||||
* Should tenant auto created.
|
||||
*
|
||||
* @return <true> = auto create <false> not create
|
||||
*/
|
||||
boolean autoCreateTenant() default true;
|
||||
|
||||
/**
|
||||
* Gets the test authorities.
|
||||
*
|
||||
* @return authorities
|
||||
*/
|
||||
String[] authorities() default {};
|
||||
|
||||
/**
|
||||
* Gets the test all permissions.
|
||||
*
|
||||
* @return permissions
|
||||
*/
|
||||
boolean allSpPermissions() default false;
|
||||
|
||||
/**
|
||||
* Gets the test removeFromAllPermission.
|
||||
*
|
||||
* @return removeFromAllPermission
|
||||
*/
|
||||
String[] removeFromAllPermission() default {};
|
||||
}
|
||||
@@ -10,7 +10,7 @@ package org.eclipse.hawkbit.repository.jpa.model;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
|
||||
import org.eclipse.hawkbit.repository.jpa.AbstractIntegrationTest;
|
||||
import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -20,7 +20,7 @@ import ru.yandex.qatools.allure.annotations.Stories;
|
||||
|
||||
@Features("Unit Tests - Repository")
|
||||
@Stories("Repository Model")
|
||||
public class ModelEqualsHashcodeTest extends AbstractIntegrationTest {
|
||||
public class ModelEqualsHashcodeTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
@Test
|
||||
@Description("Verfies that different objects even with identical primary key, version and tenant "
|
||||
|
||||
@@ -13,7 +13,7 @@ import static org.junit.Assert.fail;
|
||||
|
||||
import org.eclipse.hawkbit.repository.ActionFields;
|
||||
import org.eclipse.hawkbit.repository.exception.RSQLParameterUnsupportedFieldException;
|
||||
import org.eclipse.hawkbit.repository.jpa.AbstractIntegrationTest;
|
||||
import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaAction;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
@@ -30,7 +30,7 @@ import ru.yandex.qatools.allure.annotations.Stories;
|
||||
|
||||
@Features("Component Tests - Repository")
|
||||
@Stories("RSQL filter actions")
|
||||
public class RSQLActionFieldsTest extends AbstractIntegrationTest {
|
||||
public class RSQLActionFieldsTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
private Target target;
|
||||
private JpaAction action;
|
||||
|
||||
@@ -15,12 +15,12 @@ import java.util.Arrays;
|
||||
|
||||
import org.eclipse.hawkbit.repository.DistributionSetFields;
|
||||
import org.eclipse.hawkbit.repository.exception.RSQLParameterSyntaxException;
|
||||
import org.eclipse.hawkbit.repository.jpa.AbstractIntegrationTest;
|
||||
import org.eclipse.hawkbit.repository.jpa.TestDataUtil;
|
||||
import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetMetadata;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetTag;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetTag;
|
||||
import org.eclipse.hawkbit.repository.util.TestdataFactory;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.domain.Page;
|
||||
@@ -32,19 +32,18 @@ import ru.yandex.qatools.allure.annotations.Stories;
|
||||
|
||||
@Features("Component Tests - Repository")
|
||||
@Stories("RSQL filter distribution set")
|
||||
public class RSQLDistributionSetFieldTest extends AbstractIntegrationTest {
|
||||
public class RSQLDistributionSetFieldTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
@Before
|
||||
public void seuptBeforeTest() {
|
||||
|
||||
DistributionSet ds = TestDataUtil.generateDistributionSet("DS", softwareManagement, distributionSetManagement);
|
||||
DistributionSet ds = testdataFactory.createDistributionSet("DS");
|
||||
ds.setDescription("DS");
|
||||
ds = distributionSetManagement.updateDistributionSet(ds);
|
||||
distributionSetManagement
|
||||
.createDistributionSetMetadata(new JpaDistributionSetMetadata("metaKey", ds, "metaValue"));
|
||||
|
||||
DistributionSet ds2 = TestDataUtil
|
||||
.generateDistributionSets("NewDS", 3, softwareManagement, distributionSetManagement).get(0);
|
||||
DistributionSet ds2 = testdataFactory.createDistributionSets("NewDS", 3).get(0);
|
||||
|
||||
ds2.setDescription("DS%");
|
||||
ds2 = distributionSetManagement.updateDistributionSet(ds2);
|
||||
@@ -89,10 +88,12 @@ public class RSQLDistributionSetFieldTest extends AbstractIntegrationTest {
|
||||
@Test
|
||||
@Description("Test filter distribution set by version")
|
||||
public void testFilterByParameterVersion() {
|
||||
assertRSQLQuery(DistributionSetFields.VERSION.name() + "==v1.0", 2);
|
||||
assertRSQLQuery(DistributionSetFields.VERSION.name() + "!=v1.0", 2);
|
||||
assertRSQLQuery(DistributionSetFields.VERSION.name() + "=in=(v1.0,v1.1)", 3);
|
||||
assertRSQLQuery(DistributionSetFields.VERSION.name() + "=out=(v1.0,error)", 2);
|
||||
assertRSQLQuery(DistributionSetFields.VERSION.name() + "==" + TestdataFactory.DEFAULT_VERSION, 1);
|
||||
assertRSQLQuery(DistributionSetFields.VERSION.name() + "!=" + TestdataFactory.DEFAULT_VERSION, 3);
|
||||
assertRSQLQuery(
|
||||
DistributionSetFields.VERSION.name() + "=in=(" + TestdataFactory.DEFAULT_VERSION + ",1.0.0,1.0.1)", 3);
|
||||
assertRSQLQuery(DistributionSetFields.VERSION.name() + "=out=(" + TestdataFactory.DEFAULT_VERSION + ",error)",
|
||||
3);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -121,10 +122,10 @@ public class RSQLDistributionSetFieldTest extends AbstractIntegrationTest {
|
||||
@Test
|
||||
@Description("Test filter distribution set by type")
|
||||
public void testFilterByType() {
|
||||
assertRSQLQuery(DistributionSetFields.TYPE.name() + "==ecl_os_app_jvm", 4);
|
||||
assertRSQLQuery(DistributionSetFields.TYPE.name() + "==" + TestdataFactory.DS_TYPE_DEFAULT, 4);
|
||||
assertRSQLQuery(DistributionSetFields.TYPE.name() + "==noExist*", 0);
|
||||
assertRSQLQuery(DistributionSetFields.TYPE.name() + "=in=(ecl_os_app_jvm,ecl)", 4);
|
||||
assertRSQLQuery(DistributionSetFields.TYPE.name() + "=out=(ecl_os_app_jvm)", 0);
|
||||
assertRSQLQuery(DistributionSetFields.TYPE.name() + "=in=(" + TestdataFactory.DS_TYPE_DEFAULT + ",ecl)", 4);
|
||||
assertRSQLQuery(DistributionSetFields.TYPE.name() + "=out=(" + TestdataFactory.DS_TYPE_DEFAULT + ")", 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -14,8 +14,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.hawkbit.repository.DistributionSetMetadataFields;
|
||||
import org.eclipse.hawkbit.repository.jpa.AbstractIntegrationTest;
|
||||
import org.eclipse.hawkbit.repository.jpa.TestDataUtil;
|
||||
import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetMetadata;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetMetadata;
|
||||
@@ -30,14 +29,13 @@ import ru.yandex.qatools.allure.annotations.Stories;
|
||||
|
||||
@Features("Component Tests - Repository")
|
||||
@Stories("RSQL filter distribution set metadata")
|
||||
public class RSQLDistributionSetMetadataFieldsTest extends AbstractIntegrationTest {
|
||||
public class RSQLDistributionSetMetadataFieldsTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
private Long distributionSetId;
|
||||
|
||||
@Before
|
||||
public void setupBeforeTest() {
|
||||
final DistributionSet distributionSet = TestDataUtil.generateDistributionSet("DS", softwareManagement,
|
||||
distributionSetManagement);
|
||||
final DistributionSet distributionSet = testdataFactory.createDistributionSet("DS");
|
||||
distributionSetId = distributionSet.getId();
|
||||
|
||||
final List<DistributionSetMetadata> metadata = new ArrayList<>();
|
||||
|
||||
@@ -11,8 +11,7 @@ package org.eclipse.hawkbit.repository.jpa.rsql;
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
|
||||
import org.eclipse.hawkbit.repository.RolloutGroupFields;
|
||||
import org.eclipse.hawkbit.repository.jpa.AbstractIntegrationTest;
|
||||
import org.eclipse.hawkbit.repository.jpa.TestDataUtil;
|
||||
import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaRollout;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.Rollout;
|
||||
@@ -30,7 +29,7 @@ import ru.yandex.qatools.allure.annotations.Stories;
|
||||
|
||||
@Features("Component Tests - Repository")
|
||||
@Stories("RSQL filter rollout group")
|
||||
public class RSQLRolloutGroupFields extends AbstractIntegrationTest {
|
||||
public class RSQLRolloutGroupFields extends AbstractJpaIntegrationTest {
|
||||
|
||||
private Long rolloutGroupId;
|
||||
private Rollout rollout;
|
||||
@@ -38,9 +37,8 @@ public class RSQLRolloutGroupFields extends AbstractIntegrationTest {
|
||||
@Before
|
||||
public void seuptBeforeTest() {
|
||||
final int amountTargets = 20;
|
||||
targetManagement.createTargets(TestDataUtil.buildTargetFixtures(amountTargets, "rollout", "rollout"));
|
||||
final DistributionSet dsA = TestDataUtil.generateDistributionSet("", softwareManagement,
|
||||
distributionSetManagement);
|
||||
targetManagement.createTargets(testdataFactory.generateTargets(amountTargets, "rollout", "rollout"));
|
||||
final DistributionSet dsA = testdataFactory.createDistributionSet("");
|
||||
rollout = createRollout("rollout1", 4, dsA.getId(), "controllerId==rollout*");
|
||||
rollout = rolloutManagement.findRolloutById(rollout.getId());
|
||||
this.rolloutGroupId = rollout.getRolloutGroups().get(0).getId();
|
||||
|
||||
@@ -11,7 +11,7 @@ package org.eclipse.hawkbit.repository.jpa.rsql;
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
|
||||
import org.eclipse.hawkbit.repository.SoftwareModuleFields;
|
||||
import org.eclipse.hawkbit.repository.jpa.AbstractIntegrationTest;
|
||||
import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleMetadata;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
@@ -27,7 +27,7 @@ import ru.yandex.qatools.allure.annotations.Stories;
|
||||
|
||||
@Features("Component Tests - Repository")
|
||||
@Stories("RSQL filter software module")
|
||||
public class RSQLSoftwareModuleFieldTest extends AbstractIntegrationTest {
|
||||
public class RSQLSoftwareModuleFieldTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
@Before
|
||||
public void setupBeforeTest() {
|
||||
|
||||
@@ -14,12 +14,11 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.hawkbit.repository.SoftwareModuleMetadataFields;
|
||||
import org.eclipse.hawkbit.repository.jpa.AbstractIntegrationTest;
|
||||
import org.eclipse.hawkbit.repository.jpa.TestDataUtil;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleMetadata;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModuleMetadata;
|
||||
import org.eclipse.hawkbit.repository.util.TestdataFactory;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.domain.Page;
|
||||
@@ -31,15 +30,14 @@ import ru.yandex.qatools.allure.annotations.Stories;
|
||||
|
||||
@Features("Component Tests - Repository")
|
||||
@Stories("RSQL filter software module metadata")
|
||||
public class RSQLSoftwareModuleMetadataFieldsTest extends AbstractIntegrationTest {
|
||||
public class RSQLSoftwareModuleMetadataFieldsTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
private Long softwareModuleId;
|
||||
|
||||
@Before
|
||||
public void setupBeforeTest() {
|
||||
final SoftwareModule softwareModule = softwareManagement.createSoftwareModule(
|
||||
new JpaSoftwareModule(TestDataUtil.findOrCreateSoftwareModuleType(softwareManagement, "application"),
|
||||
"application", "1.0.0", "Desc", "vendor Limited, California"));
|
||||
final SoftwareModule softwareModule = testdataFactory.createSoftwareModule(TestdataFactory.SM_TYPE_APP);
|
||||
|
||||
softwareModuleId = softwareModule.getId();
|
||||
|
||||
final List<SoftwareModuleMetadata> metadata = new ArrayList<>();
|
||||
|
||||
@@ -11,7 +11,7 @@ package org.eclipse.hawkbit.repository.jpa.rsql;
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
|
||||
import org.eclipse.hawkbit.repository.SoftwareModuleTypeFields;
|
||||
import org.eclipse.hawkbit.repository.jpa.AbstractIntegrationTest;
|
||||
import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.domain.Page;
|
||||
@@ -23,7 +23,7 @@ import ru.yandex.qatools.allure.annotations.Stories;
|
||||
|
||||
@Features("Component Tests - Repository")
|
||||
@Stories("RSQL filter software module test type")
|
||||
public class RSQLSoftwareModuleTypeFieldsTest extends AbstractIntegrationTest {
|
||||
public class RSQLSoftwareModuleTypeFieldsTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
@Test
|
||||
@Description("Test filter software module test type by id")
|
||||
@@ -34,7 +34,7 @@ public class RSQLSoftwareModuleTypeFieldsTest extends AbstractIntegrationTest {
|
||||
@Test
|
||||
@Description("Test filter software module test type by name")
|
||||
public void testFilterByParameterName() {
|
||||
assertRSQLQuery(SoftwareModuleTypeFields.NAME.name() + "==ECL*", 3);
|
||||
assertRSQLQuery(SoftwareModuleTypeFields.NAME.name() + "==Firmware", 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -55,7 +55,7 @@ public class RSQLSoftwareModuleTypeFieldsTest extends AbstractIntegrationTest {
|
||||
@Test
|
||||
@Description("Test filter software module test type by max")
|
||||
public void testFilterByMaxAssignment() {
|
||||
assertRSQLQuery(SoftwareModuleTypeFields.MAXASSIGNMENTS.name() + "==1", 3);
|
||||
assertRSQLQuery(SoftwareModuleTypeFields.MAXASSIGNMENTS.name() + "==1", 2);
|
||||
}
|
||||
|
||||
private void assertRSQLQuery(final String rsqlParam, final long excpectedEntity) {
|
||||
|
||||
@@ -11,7 +11,7 @@ package org.eclipse.hawkbit.repository.jpa.rsql;
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
|
||||
import org.eclipse.hawkbit.repository.TagFields;
|
||||
import org.eclipse.hawkbit.repository.jpa.AbstractIntegrationTest;
|
||||
import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetTag;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetTag;
|
||||
@@ -27,7 +27,7 @@ import ru.yandex.qatools.allure.annotations.Stories;
|
||||
|
||||
@Features("Component Tests - Repository")
|
||||
@Stories("RSQL filter target and distribution set tags")
|
||||
public class RSQLTagFieldsTest extends AbstractIntegrationTest {
|
||||
public class RSQLTagFieldsTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
@Before
|
||||
public void seuptBeforeTest() {
|
||||
|
||||
@@ -15,8 +15,7 @@ import java.util.Arrays;
|
||||
|
||||
import org.eclipse.hawkbit.repository.TargetFields;
|
||||
import org.eclipse.hawkbit.repository.exception.RSQLParameterUnsupportedFieldException;
|
||||
import org.eclipse.hawkbit.repository.jpa.AbstractIntegrationTest;
|
||||
import org.eclipse.hawkbit.repository.jpa.TestDataUtil;
|
||||
import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetInfo;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag;
|
||||
@@ -25,6 +24,7 @@ import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.model.TargetInfo;
|
||||
import org.eclipse.hawkbit.repository.model.TargetTag;
|
||||
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
|
||||
import org.eclipse.hawkbit.repository.util.TestdataFactory;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.domain.Page;
|
||||
@@ -36,19 +36,17 @@ import ru.yandex.qatools.allure.annotations.Stories;
|
||||
|
||||
@Features("Component Tests - Repository")
|
||||
@Stories("RSQL filter target")
|
||||
public class RSQLTargetFieldTest extends AbstractIntegrationTest {
|
||||
public class RSQLTargetFieldTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
@Before
|
||||
public void seuptBeforeTest() {
|
||||
|
||||
final DistributionSet ds = TestDataUtil.generateDistributionSet("AssignedDs", softwareManagement,
|
||||
distributionSetManagement);
|
||||
final DistributionSet ds = testdataFactory.createDistributionSet("AssignedDs");
|
||||
|
||||
final JpaTarget target = new JpaTarget("targetId123");
|
||||
final Target target = entityFactory.generateTarget("targetId123");
|
||||
target.setDescription("targetId123");
|
||||
final TargetInfo targetInfo = new JpaTargetInfo(target);
|
||||
final TargetInfo targetInfo = target.getTargetInfo();
|
||||
targetInfo.getControllerAttributes().put("revision", "1.1");
|
||||
target.setTargetInfo(targetInfo);
|
||||
((JpaTargetInfo) target.getTargetInfo()).setUpdateStatus(TargetUpdateStatus.PENDING);
|
||||
|
||||
targetManagement.createTarget(target);
|
||||
@@ -149,11 +147,13 @@ public class RSQLTargetFieldTest extends AbstractIntegrationTest {
|
||||
@Test
|
||||
@Description("Test filter target by assigned ds version")
|
||||
public void testFilterByAssignedDsVersion() {
|
||||
assertRSQLQuery(TargetFields.ASSIGNEDDS.name() + ".version==v1.0", 1);
|
||||
assertRSQLQuery(TargetFields.ASSIGNEDDS.name() + ".version==" + TestdataFactory.DEFAULT_VERSION, 1);
|
||||
assertRSQLQuery(TargetFields.ASSIGNEDDS.name() + ".version==*1*", 1);
|
||||
assertRSQLQuery(TargetFields.ASSIGNEDDS.name() + ".version==noExist*", 0);
|
||||
assertRSQLQuery(TargetFields.ASSIGNEDDS.name() + ".version=in=(v1.0,notexist)", 1);
|
||||
assertRSQLQuery(TargetFields.ASSIGNEDDS.name() + ".version=out=(v1.0,notexist)", 0);
|
||||
assertRSQLQuery(
|
||||
TargetFields.ASSIGNEDDS.name() + ".version=in=(" + TestdataFactory.DEFAULT_VERSION + ",notexist)", 1);
|
||||
assertRSQLQuery(
|
||||
TargetFields.ASSIGNEDDS.name() + ".version=out=(" + TestdataFactory.DEFAULT_VERSION + ",notexist)", 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -10,14 +10,14 @@ package org.eclipse.hawkbit.repository.jpa.tenancy;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
|
||||
import org.eclipse.hawkbit.repository.jpa.AbstractIntegrationTest;
|
||||
import org.eclipse.hawkbit.repository.jpa.WithSpringAuthorityRule;
|
||||
import org.eclipse.hawkbit.repository.jpa.WithUser;
|
||||
import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetType;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.util.WithSpringAuthorityRule;
|
||||
import org.eclipse.hawkbit.repository.util.WithUser;
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Slice;
|
||||
@@ -34,7 +34,7 @@ import ru.yandex.qatools.allure.annotations.Stories;
|
||||
*/
|
||||
@Features("Component Tests - Repository")
|
||||
@Stories("Multi Tenancy")
|
||||
public class MultiTenancyEntityTest extends AbstractIntegrationTest {
|
||||
public class MultiTenancyEntityTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
@Test
|
||||
@Description(value = "Ensures that multiple targets with same controller-ID can be created for different tenants.")
|
||||
|
||||
@@ -1,485 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa.utils;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.Query;
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
import org.eclipse.hawkbit.im.authentication.SpPermission;
|
||||
import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions;
|
||||
import org.eclipse.hawkbit.im.authentication.TenantAwareAuthenticationDetails;
|
||||
import org.eclipse.hawkbit.repository.ControllerManagement;
|
||||
import org.eclipse.hawkbit.repository.DeploymentManagement;
|
||||
import org.eclipse.hawkbit.repository.DistributionSetAssignmentResult;
|
||||
import org.eclipse.hawkbit.repository.DistributionSetManagement;
|
||||
import org.eclipse.hawkbit.repository.SoftwareManagement;
|
||||
import org.eclipse.hawkbit.repository.TagManagement;
|
||||
import org.eclipse.hawkbit.repository.TargetManagement;
|
||||
import org.eclipse.hawkbit.repository.jpa.TestDataUtil;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetTag;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleType;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag;
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.Action.Status;
|
||||
import org.eclipse.hawkbit.repository.model.ActionStatus;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetTag;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.model.TargetTag;
|
||||
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
|
||||
import org.eclipse.hawkbit.util.IpUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.data.auditing.AuditingHandler;
|
||||
import org.springframework.data.jpa.repository.Modifying;
|
||||
import org.springframework.security.authentication.TestingAuthenticationToken;
|
||||
import org.springframework.security.core.context.SecurityContext;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.security.core.context.SecurityContextImpl;
|
||||
|
||||
import net._01001111.text.LoremIpsum;
|
||||
|
||||
/**
|
||||
* Generates test data for setting up the repository for test or demonstration
|
||||
* purpose.
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
public final class RepositoryDataGenerator {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(RepositoryDataGenerator.class);
|
||||
|
||||
public static void initDemoRepo(final ConfigurableApplicationContext context) {
|
||||
final PersistentInitDemoDataBuilder initDemoDataBuilder = new PersistentInitDemoDataBuilder(context);
|
||||
initDemoDataBuilder.initDemoRepo(20, 0);
|
||||
}
|
||||
|
||||
public static void initLoadRepo(final ConfigurableApplicationContext context) {
|
||||
final PersistentInitDemoDataBuilder initDemoDataBuilder = new PersistentInitDemoDataBuilder(context);
|
||||
initDemoDataBuilder.initDemoRepo(200, 200);
|
||||
}
|
||||
|
||||
/**
|
||||
* builder which build initial demo data and stores it to the repos.
|
||||
*
|
||||
*/
|
||||
private static final class PersistentInitDemoDataBuilder {
|
||||
|
||||
private final SoftwareManagement softwareManagement;
|
||||
private final TargetManagement targetManagement;
|
||||
private final DeploymentManagement deploymentManagement;
|
||||
private final TagManagement tagManagement;
|
||||
private final ControllerManagement controllerManagement;
|
||||
private final DistributionSetManagement distributionSetManagement;
|
||||
|
||||
private final DatabaseCleanupUtil dbCleanupUtil;
|
||||
|
||||
private final AuditingHandler auditingHandler;
|
||||
|
||||
final LoremIpsum jlorem = new LoremIpsum();
|
||||
|
||||
PersistentInitDemoDataBuilder(final ConfigurableApplicationContext context) {
|
||||
softwareManagement = context.getBean(SoftwareManagement.class);
|
||||
targetManagement = context.getBean(TargetManagement.class);
|
||||
tagManagement = context.getBean(TagManagement.class);
|
||||
deploymentManagement = context.getBean(DeploymentManagement.class);
|
||||
controllerManagement = context.getBean(ControllerManagement.class);
|
||||
distributionSetManagement = context.getBean(DistributionSetManagement.class);
|
||||
|
||||
dbCleanupUtil = context.getBean(DatabaseCleanupUtil.class);
|
||||
|
||||
auditingHandler = context.getBean(AuditingHandler.class);
|
||||
}
|
||||
|
||||
private void runAsAllAuthorityContext(final Runnable runnable) {
|
||||
final SecurityContext oldContext = SecurityContextHolder.getContext();
|
||||
try {
|
||||
final SecurityContextImpl securityContextImpl = new SecurityContextImpl();
|
||||
final TestingAuthenticationToken authentication = new TestingAuthenticationToken("repogenator",
|
||||
"repogenator", SpPermission.CREATE_REPOSITORY, SpPermission.CREATE_TARGET,
|
||||
SpPermission.DELETE_REPOSITORY, SpPermission.DELETE_TARGET, SpPermission.READ_REPOSITORY,
|
||||
SpPermission.READ_TARGET, SpPermission.UPDATE_REPOSITORY, SpPermission.UPDATE_TARGET,
|
||||
SpringEvalExpressions.CONTROLLER_ROLE);
|
||||
securityContextImpl.setAuthentication(authentication);
|
||||
authentication.setDetails(new TenantAwareAuthenticationDetails("default", false));
|
||||
SecurityContextHolder.setContext(securityContextImpl);
|
||||
runnable.run();
|
||||
} finally {
|
||||
SecurityContextHolder.setContext(oldContext);
|
||||
}
|
||||
}
|
||||
|
||||
public void generateTestTagetGroup(final String group, final int sizeMultiplikator) {
|
||||
final DistributionSetTag dsTag = tagManagement
|
||||
.createDistributionSetTag(new JpaDistributionSetTag("For " + group + "s"));
|
||||
|
||||
auditingHandler.setDateTimeProvider(() -> {
|
||||
final Calendar instance = Calendar.getInstance();
|
||||
instance.add(Calendar.MONTH, -new Random().nextInt(7));
|
||||
|
||||
return instance;
|
||||
});
|
||||
|
||||
final List<Target> targets = createTargetTestGroup(group, 20 * sizeMultiplikator);
|
||||
|
||||
auditingHandler.setDateTimeProvider(() -> {
|
||||
final Calendar instance = Calendar.getInstance();
|
||||
return instance;
|
||||
});
|
||||
|
||||
LOG.debug("initDemoRepo - start now real action history for group: {}", group);
|
||||
|
||||
// Old history of succesfully finished operations
|
||||
IntStream.range(0, 10).forEach(idx -> {
|
||||
final DistributionSet dsReal = TestDataUtil.generateDistributionSet(group + " Release", "v1." + idx,
|
||||
softwareManagement, distributionSetManagement,
|
||||
Arrays.asList(new DistributionSetTag[] { dsTag }));
|
||||
|
||||
final DistributionSetAssignmentResult result = deploymentManagement.assignDistributionSet(dsReal,
|
||||
targets);
|
||||
|
||||
createSimpleActionStatusHistory(result.getActions());
|
||||
});
|
||||
|
||||
final List<List<Target>> targetGroups = splitIntoGroups(targets);
|
||||
|
||||
IntStream.range(0, targetGroups.size()).forEach(idx -> {
|
||||
final DistributionSet dsReal = TestDataUtil.generateDistributionSet(group + " Release", "v2." + idx,
|
||||
softwareManagement, distributionSetManagement,
|
||||
Arrays.asList(new DistributionSetTag[] { dsTag }));
|
||||
|
||||
final DistributionSetAssignmentResult result = deploymentManagement.assignDistributionSet(dsReal,
|
||||
targetGroups.get(idx));
|
||||
|
||||
createActionStatusHistory(result.getActions(), sizeMultiplikator);
|
||||
});
|
||||
|
||||
LOG.debug("initDemoRepo - real action history finished for group: {}", group);
|
||||
}
|
||||
|
||||
private List<List<Target>> splitIntoGroups(final List<Target> allTargets) {
|
||||
|
||||
final int elements = allTargets.size();
|
||||
|
||||
final int group1 = elements * (5 + new Random().nextInt(5)) / 100;
|
||||
final int group2 = elements * (15 + new Random().nextInt(5)) / 100;
|
||||
|
||||
final List<List<Target>> result = new ArrayList<List<Target>>();
|
||||
|
||||
result.add(allTargets.subList(0, group1));
|
||||
result.add(allTargets.subList(group1, group2));
|
||||
result.add(allTargets.subList(group2, elements));
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
private void createActionStatusHistory(final List<Long> actions, final int sizeMultiplikator) {
|
||||
final AtomicInteger counter = new AtomicInteger();
|
||||
|
||||
int index = 0;
|
||||
for (final Long actionGiven : actions) {
|
||||
// retrieved
|
||||
Action action = controllerManagement.registerRetrieved(
|
||||
deploymentManagement.findActionWithDetails(actionGiven),
|
||||
"Controller retrieved update action and should start now the download.");
|
||||
|
||||
// download
|
||||
final ActionStatus download = new JpaActionStatus();
|
||||
download.setAction(action);
|
||||
download.setStatus(Status.DOWNLOAD);
|
||||
download.addMessage("Controller started download.");
|
||||
action = controllerManagement.addUpdateActionStatus(download);
|
||||
|
||||
// warning
|
||||
final ActionStatus warning = new JpaActionStatus();
|
||||
warning.setAction(action);
|
||||
warning.setStatus(Status.WARNING);
|
||||
warning.addMessage("Some warning: " + jlorem.words(new Random().nextInt(50)));
|
||||
action = controllerManagement.addUpdateActionStatus(warning);
|
||||
|
||||
// garbage
|
||||
for (int i = 0; i < new Random().nextInt(10); i++) {
|
||||
final ActionStatus running = new JpaActionStatus();
|
||||
running.setAction(action);
|
||||
running.setStatus(Status.RUNNING);
|
||||
running.addMessage("Still running: " + jlorem.words(new Random().nextInt(50)));
|
||||
action = controllerManagement.addUpdateActionStatus(running);
|
||||
for (int g = 0; g < new Random().nextInt(5); g++) {
|
||||
final ActionStatus rand = new JpaActionStatus();
|
||||
rand.setAction(action);
|
||||
rand.setStatus(Status.RUNNING);
|
||||
rand.addMessage(jlorem.words(new Random().nextInt(50)));
|
||||
action = controllerManagement.addUpdateActionStatus(rand);
|
||||
}
|
||||
}
|
||||
|
||||
// close
|
||||
final ActionStatus close = new JpaActionStatus();
|
||||
close.setAction(action);
|
||||
|
||||
// with error
|
||||
final int incrementAndGet = counter.incrementAndGet();
|
||||
if (incrementAndGet % 5 == 0) {
|
||||
close.setStatus(Status.ERROR);
|
||||
close.addMessage("Controller reported CLOSED with ERROR!");
|
||||
action = controllerManagement.addUpdateActionStatus(close);
|
||||
}
|
||||
// with OK
|
||||
else {
|
||||
close.setStatus(Status.FINISHED);
|
||||
close.addMessage("Controller reported CLOSED with OK!");
|
||||
action = controllerManagement.addUpdateActionStatus(close);
|
||||
}
|
||||
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
private void createSimpleActionStatusHistory(final List<Long> actions) {
|
||||
for (final Long actionGiven : actions) {
|
||||
// retrieved
|
||||
Action action = controllerManagement.registerRetrieved(
|
||||
deploymentManagement.findActionWithDetails(actionGiven),
|
||||
"Controller retrieved update action and should start now the download.");
|
||||
|
||||
// close
|
||||
final ActionStatus close = new JpaActionStatus();
|
||||
close.setAction(action);
|
||||
close.setStatus(Status.FINISHED);
|
||||
close.addMessage("Controller reported CLOSED with OK!");
|
||||
action = controllerManagement.addUpdateActionStatus(close);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private List<Target> createTargetTestGroup(final String group, final int targets) {
|
||||
LOG.debug("createTargetTestGroup: create group {}", group);
|
||||
|
||||
final TargetTag targTag = tagManagement.createTargetTag(new JpaTargetTag(group));
|
||||
|
||||
final List<Target> targAs = targetManagement.createTargets(buildTargets(targets, group),
|
||||
TargetUpdateStatus.REGISTERED, System.currentTimeMillis() - new Random().nextInt(50_000_000),
|
||||
generateIPAddress());
|
||||
LOG.debug("createTargetTestGroup: {} created", group);
|
||||
|
||||
LOG.debug("createTargetTestGroup: {} targets status updated including IP", group);
|
||||
|
||||
return targetManagement.toggleTagAssignment(targAs, targTag).getAssignedEntity();
|
||||
}
|
||||
|
||||
private List<Target> buildTargets(final int noOfTgts, final String descriptionPrefix) {
|
||||
|
||||
final List<Target> result = new ArrayList<Target>(noOfTgts);
|
||||
|
||||
for (int i = 0; i < noOfTgts; i++) {
|
||||
final Target target = new JpaTarget(UUID.randomUUID().toString());
|
||||
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
builder.append(descriptionPrefix);
|
||||
builder.append(jlorem.words(5));
|
||||
|
||||
target.setDescription(builder.toString());
|
||||
target.getTargetInfo().getControllerAttributes().put("revision", "1.1");
|
||||
target.getTargetInfo().getControllerAttributes().put("capacity", "128M");
|
||||
target.getTargetInfo().getControllerAttributes().put("serial",
|
||||
String.valueOf(System.currentTimeMillis()));
|
||||
|
||||
result.add(target);
|
||||
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* method writes initial test/demo data to the repositories.
|
||||
*
|
||||
* @param sizeMultiplikator
|
||||
* the entire scenario
|
||||
* @param loadtestgroups
|
||||
* packages of 1_000 targets
|
||||
*/
|
||||
private void initDemoRepo(final int sizeMultiplikator, final int loadtestgroups) {
|
||||
final LoremIpsum jlorem = new LoremIpsum();
|
||||
|
||||
runAsAllAuthorityContext(() -> {
|
||||
dbCleanupUtil.cleanupDB(null);
|
||||
|
||||
// generate targets and assign DS
|
||||
// 5 groups - 100 targets each -> 500
|
||||
final String[] targetTestGroups = { "SHC", "CCU", "Vehicle", "Vending machine", "ECU" };
|
||||
|
||||
final String[] modulesTypes = { "HeadUnit_FW", "EDC17_FW", "OSGi_Bundle" };
|
||||
|
||||
final DistributionSetTag depTag = tagManagement
|
||||
.createDistributionSetTag(new JpaDistributionSetTag("deprecated"));
|
||||
|
||||
Arrays.stream(targetTestGroups).forEach(group -> {
|
||||
generateTestTagetGroup(group, sizeMultiplikator);
|
||||
});
|
||||
|
||||
// garbage DS
|
||||
LOG.debug("initDemoRepo - start now DS garbage");
|
||||
TestDataUtil.generateDistributionSets("Generic Software Package", sizeMultiplikator, softwareManagement,
|
||||
distributionSetManagement);
|
||||
LOG.debug("initDemoRepo - DS garbage finished");
|
||||
|
||||
LOG.debug("initDemoRepo - start now Extra Software Modules and types");
|
||||
Arrays.stream(modulesTypes).forEach(typeName -> {
|
||||
final SoftwareModuleType smtype = softwareManagement.createSoftwareModuleType(
|
||||
new JpaSoftwareModuleType(typeName.toLowerCase().replaceAll("\\s+", ""), typeName,
|
||||
jlorem.words(5), Integer.MAX_VALUE));
|
||||
|
||||
for (int i1 = 0; i1 < sizeMultiplikator; i1++) {
|
||||
softwareManagement.createSoftwareModule(new JpaSoftwareModule(smtype, typeName + i1, "1.0." + i1,
|
||||
jlorem.words(5), "the " + typeName + " vendor Inc."));
|
||||
}
|
||||
|
||||
});
|
||||
LOG.debug("initDemoRepo - Extra Software Modules and types finished");
|
||||
|
||||
LOG.debug("initDemoRepo - start now target garbage");
|
||||
|
||||
// garbage targets
|
||||
// unknown
|
||||
targetManagement
|
||||
.createTargets(TestDataUtil.generateTargets(targetTestGroups.length * sizeMultiplikator));
|
||||
|
||||
// registered
|
||||
targetManagement.createTargets(
|
||||
TestDataUtil.generateTargets(targetTestGroups.length * sizeMultiplikator, "registered"),
|
||||
TargetUpdateStatus.REGISTERED, System.currentTimeMillis(), generateIPAddress());
|
||||
|
||||
// pending
|
||||
final DistributionSetTag dsTag = tagManagement
|
||||
.createDistributionSetTag(new JpaDistributionSetTag("OnlyAssignedTag"));
|
||||
final DistributionSet ds = TestDataUtil.generateDistributionSet("Pending DS", "v1.0",
|
||||
softwareManagement, distributionSetManagement,
|
||||
Arrays.asList(new DistributionSetTag[] { dsTag }));
|
||||
deploymentManagement.assignDistributionSet(ds, targetManagement.createTargets(
|
||||
TestDataUtil.generateTargets(targetTestGroups.length * sizeMultiplikator, "pending")));
|
||||
|
||||
// Load test means additional 1_000_000 target
|
||||
|
||||
for (int i2 = 0; i2 < loadtestgroups; i2++) {
|
||||
targetManagement.createTargets(TestDataUtil.generateTargets(i2 * 1_000, 1_000, "loadtest-"));
|
||||
}
|
||||
|
||||
LOG.debug("initDemoRepo complete");
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Adding controller attributes for given {@link Target}.
|
||||
*/
|
||||
// private Target setControllerAttributes( final String targetId ) {
|
||||
// final Target target =
|
||||
// targetManagement.findTargetByControllerIDWithDetails( targetId );
|
||||
// target.getTargetStatus().getControllerAttributes().put( "revision",
|
||||
// "1.1" );
|
||||
// target.getTargetStatus().getControllerAttributes().put( "capacity",
|
||||
// "128M" );
|
||||
// target.getTargetStatus().getControllerAttributes().put( "serial",
|
||||
// String.valueOf(
|
||||
// System.currentTimeMillis()) );
|
||||
// return targetManagement.updateTarget( target );
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Data clean up class.
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
public static class DatabaseCleanupUtil {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(DatabaseCleanupUtil.class);
|
||||
@Autowired
|
||||
private EntityManager entityManager;
|
||||
|
||||
private static final String[] CLEAN_UP_SQLS = new String[] { "sp_tenant", "sp_tenant_configuration",
|
||||
"sp_artifact", "sp_external_artifact", "sp_external_provider", "sp_target_target_tag",
|
||||
"sp_target_attributes", "sp_target_tag", "sp_action_status_messages", "sp_action_status", "sp_action",
|
||||
"sp_ds_dstag", "sp_distributionset_tag", "sp_target_info", "sp_target", "sp_sw_metadata",
|
||||
"sp_ds_metadata", "sp_ds_module", "sp_distribution_set", "sp_base_software_module",
|
||||
"sp_ds_type_element", "sp_distribution_set_type", "sp_software_module_type" };
|
||||
|
||||
/**
|
||||
* delete all entries from the DB tables.
|
||||
*/
|
||||
@Transactional
|
||||
@Modifying
|
||||
public void cleanupDB(final String database) {
|
||||
LOG.debug("Data clean up is started...");
|
||||
final boolean isMySql = "MYSQL".equals(database);
|
||||
if (isMySql) {
|
||||
// disable foreign key check because otherwise mysql cannot
|
||||
// delete sp_active_actions due
|
||||
// the self constraint within the table, stupid MySql
|
||||
entityManager.createNativeQuery("SET FOREIGN_KEY_CHECKS = 0").executeUpdate();
|
||||
}
|
||||
try {
|
||||
final String[] dbCmds = new String[] { "delete from" };
|
||||
for (final String dbCmd : dbCmds) {
|
||||
for (final String table : CLEAN_UP_SQLS) {
|
||||
final String sql = String.format("%s %s", dbCmd, table);
|
||||
final Query query = entityManager.createNativeQuery(sql);
|
||||
try {
|
||||
LOG.debug("cleanup table: {}", sql);
|
||||
LOG.debug("cleaned table: {}; deleted {} records", sql, query.executeUpdate());
|
||||
} catch (final Exception ex) {
|
||||
LOG.error(String.format("error on executing cleanup statement '%s'", sql), ex);
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LOG.debug("Data clean up is finished...");
|
||||
} finally {
|
||||
if (isMySql) {
|
||||
// enable foreign key check again!
|
||||
entityManager.createNativeQuery("SET FOREIGN_KEY_CHECKS = 1").executeUpdate();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a generated IPv4 address string.
|
||||
*/
|
||||
private static URI generateIPAddress() {
|
||||
final Random r = new Random();
|
||||
return IpUtil
|
||||
.createHttpUri(r.nextInt(256) + "." + r.nextInt(256) + "." + r.nextInt(256) + "." + r.nextInt(256));
|
||||
}
|
||||
|
||||
private RepositoryDataGenerator() {
|
||||
super();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user