refactored test data generation. Refactored entity factor methods.
Signed-off-by: Kai Zimmermann <kai.zimmermann@bosch-si.com>
This commit is contained in:
@@ -60,6 +60,12 @@ public interface ArtifactManagement {
|
||||
ExternalArtifact createExternalArtifact(@NotNull ExternalArtifactProvider externalRepository, String urlSuffix,
|
||||
@NotNull Long moduleId);
|
||||
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
|
||||
Long countLocalArtifactsAll();
|
||||
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
|
||||
Long countExternalArtifactsAll();
|
||||
|
||||
/**
|
||||
* Persists {@link ExternalArtifactProvider} based on given properties.
|
||||
*
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
package org.eclipse.hawkbit.repository;
|
||||
|
||||
import org.eclipse.hawkbit.repository.model.ActionStatus;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetType;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
|
||||
/**
|
||||
@@ -24,6 +25,12 @@ public final class Constants {
|
||||
*/
|
||||
public static final String SERVER_MESSAGE_PREFIX = "Update Server: ";
|
||||
|
||||
/**
|
||||
* Number of {@link DistributionSetType}s that are generated as part of
|
||||
* default tenant setup.
|
||||
*/
|
||||
public static final int DEFAULT_DS_TYPES_IN_TENANT = 2;
|
||||
|
||||
private Constants() {
|
||||
// Utility class.
|
||||
}
|
||||
|
||||
@@ -9,10 +9,8 @@
|
||||
package org.eclipse.hawkbit.repository;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@@ -268,61 +266,4 @@ public interface ControllerManagement {
|
||||
TargetInfo updateTargetStatus(@NotNull TargetInfo targetInfo, TargetUpdateStatus status, Long lastTargetQuery,
|
||||
URI address);
|
||||
|
||||
/**
|
||||
* Generates an empty {@link ActionStatus} object without persisting it.
|
||||
*
|
||||
* @return {@link ActionStatus} object
|
||||
*/
|
||||
ActionStatus generateActionStatus();
|
||||
|
||||
/**
|
||||
* Generates an {@link ActionStatus} object without persisting it.
|
||||
*
|
||||
* @param action
|
||||
* the {@link ActionStatus} belongs to.
|
||||
* @param status
|
||||
* as reflected by this {@link ActionStatus}.
|
||||
* @param occurredAt
|
||||
* time in {@link TimeUnit#MILLISECONDS} GMT when the status
|
||||
* change happened.
|
||||
* @param message
|
||||
* optional comment
|
||||
*
|
||||
* @return {@link ActionStatus} object
|
||||
*/
|
||||
ActionStatus generateActionStatus(Action action, Status status, Long occurredAt, final String message);
|
||||
|
||||
/**
|
||||
* Generates an {@link ActionStatus} object without persisting it.
|
||||
*
|
||||
* @param action
|
||||
* the {@link ActionStatus} belongs to.
|
||||
* @param status
|
||||
* as reflected by this {@link ActionStatus}.
|
||||
* @param occurredAt
|
||||
* time in {@link TimeUnit#MILLISECONDS} GMT when the status
|
||||
* change happened.
|
||||
* @param messages
|
||||
* optional comments
|
||||
*
|
||||
* @return {@link ActionStatus} object
|
||||
*/
|
||||
ActionStatus generateActionStatus(Action action, final Status status, Long occurredAt,
|
||||
final Collection<String> messages);
|
||||
|
||||
/**
|
||||
* Generates an {@link ActionStatus} object without persisting it.
|
||||
*
|
||||
* @param action
|
||||
* the {@link ActionStatus} belongs to.
|
||||
* @param status
|
||||
* as reflected by this {@link ActionStatus}.
|
||||
* @param occurredAt
|
||||
* time in {@link TimeUnit#MILLISECONDS} GMT when the status
|
||||
* change happened.
|
||||
*
|
||||
* @return {@link ActionStatus} object
|
||||
*/
|
||||
ActionStatus generateActionStatus(Action action, Status status, Long occurredAt);
|
||||
|
||||
}
|
||||
|
||||
@@ -187,6 +187,12 @@ public interface DeploymentManagement {
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
|
||||
Long countActionsByTarget(@NotNull String rsqlParam, @NotNull Target target);
|
||||
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
|
||||
Long countActionStatusAll();
|
||||
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
|
||||
Long countActionsAll();
|
||||
|
||||
/**
|
||||
* counts all actions associated to a specific target.
|
||||
*
|
||||
@@ -274,6 +280,9 @@ public interface DeploymentManagement {
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
|
||||
Slice<Action> findActionsByTarget(@NotNull Pageable pageable, @NotNull Target target);
|
||||
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
|
||||
Slice<Action> findActionsByDistributionSet(@NotNull Pageable pageable, @NotNull DistributionSet ds);
|
||||
|
||||
/**
|
||||
* Retrieves all {@link Action}s assigned to a specific {@link Target} and a
|
||||
* given specification.
|
||||
@@ -453,13 +462,6 @@ public interface DeploymentManagement {
|
||||
+ SpringEvalExpressions.IS_SYSTEM_CODE)
|
||||
Action startScheduledAction(@NotNull Action action);
|
||||
|
||||
/**
|
||||
* Generates an empty {@link Action} without persisting it.
|
||||
*
|
||||
* @return {@link Action} object
|
||||
*/
|
||||
Action generateAction();
|
||||
|
||||
/**
|
||||
* All {@link ActionStatus} entries in the repository.
|
||||
*
|
||||
|
||||
@@ -473,26 +473,6 @@ public interface DistributionSetManagement {
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
|
||||
DistributionSetMetadata findOne(@NotNull DistributionSet distributionSet, @NotNull String key);
|
||||
|
||||
/**
|
||||
* Generates an empty {@link DistributionSet} without persisting it.
|
||||
*
|
||||
* @return {@link DistributionSet} object
|
||||
*/
|
||||
DistributionSet generateDistributionSet();
|
||||
|
||||
DistributionSetMetadata generateDistributionSetMetadata();
|
||||
|
||||
DistributionSetMetadata generateDistributionSetMetadata(DistributionSet distributionSet, String key, String value);
|
||||
|
||||
/**
|
||||
* Generates an empty {@link DistributionSetType} without persisting it.
|
||||
*
|
||||
* @return {@link DistributionSetType} object
|
||||
*/
|
||||
DistributionSetType generateDistributionSetType();
|
||||
|
||||
DistributionSetType generateDistributionSetType(String key, String name, String description);
|
||||
|
||||
/**
|
||||
* Checks if a {@link DistributionSet} is currently in use by a target in
|
||||
* the repository.
|
||||
@@ -615,7 +595,4 @@ public interface DistributionSetManagement {
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY)
|
||||
DistributionSetType updateDistributionSetType(@NotNull DistributionSetType dsType);
|
||||
|
||||
DistributionSet generateDistributionSet(String name, String version, String description, DistributionSetType type,
|
||||
Collection<SoftwareModule> moduleList);
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,333 @@
|
||||
/**
|
||||
* 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;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
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.BaseEntity;
|
||||
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.hibernate.validator.constraints.NotEmpty;
|
||||
|
||||
/**
|
||||
* central {@link BaseEntity} generation service. Objects are created but not
|
||||
* persisted.
|
||||
*
|
||||
*/
|
||||
public interface EntityFactory {
|
||||
|
||||
/**
|
||||
* Generates an empty {@link Action} without persisting it.
|
||||
*
|
||||
* @return {@link Action} object
|
||||
*/
|
||||
Action generateAction();
|
||||
|
||||
/**
|
||||
* Generates an empty {@link ActionStatus} object without persisting it.
|
||||
*
|
||||
* @return {@link ActionStatus} object
|
||||
*/
|
||||
ActionStatus generateActionStatus();
|
||||
|
||||
/**
|
||||
* Generates an {@link ActionStatus} object without persisting it.
|
||||
*
|
||||
* @param action
|
||||
* the {@link ActionStatus} belongs to.
|
||||
* @param status
|
||||
* as reflected by this {@link ActionStatus}.
|
||||
* @param occurredAt
|
||||
* time in {@link TimeUnit#MILLISECONDS} GMT when the status
|
||||
* change happened.
|
||||
*
|
||||
* @return {@link ActionStatus} object
|
||||
*/
|
||||
ActionStatus generateActionStatus(Action action, Status status, Long occurredAt);
|
||||
|
||||
/**
|
||||
* Generates an {@link ActionStatus} object without persisting it.
|
||||
*
|
||||
* @param action
|
||||
* the {@link ActionStatus} belongs to.
|
||||
* @param status
|
||||
* as reflected by this {@link ActionStatus}.
|
||||
* @param occurredAt
|
||||
* time in {@link TimeUnit#MILLISECONDS} GMT when the status
|
||||
* change happened.
|
||||
* @param messages
|
||||
* optional comments
|
||||
*
|
||||
* @return {@link ActionStatus} object
|
||||
*/
|
||||
ActionStatus generateActionStatus(Action action, final Status status, Long occurredAt,
|
||||
final Collection<String> messages);
|
||||
|
||||
/**
|
||||
* Generates an {@link ActionStatus} object without persisting it.
|
||||
*
|
||||
* @param action
|
||||
* the {@link ActionStatus} belongs to.
|
||||
* @param status
|
||||
* as reflected by this {@link ActionStatus}.
|
||||
* @param occurredAt
|
||||
* time in {@link TimeUnit#MILLISECONDS} GMT when the status
|
||||
* change happened.
|
||||
* @param message
|
||||
* optional comment
|
||||
*
|
||||
* @return {@link ActionStatus} object
|
||||
*/
|
||||
ActionStatus generateActionStatus(Action action, Status status, Long occurredAt, final String message);
|
||||
|
||||
/**
|
||||
* Generates an empty {@link DistributionSet} without persisting it.
|
||||
*
|
||||
* @return {@link DistributionSet} object
|
||||
*/
|
||||
DistributionSet generateDistributionSet();
|
||||
|
||||
/**
|
||||
* Generates an {@link DistributionSet} without persisting it.
|
||||
*
|
||||
* @param name
|
||||
* {@link DistributionSet#getName()}
|
||||
* @param version
|
||||
* {@link DistributionSet#getVersion()}
|
||||
* @param description
|
||||
* {@link DistributionSet#getDescription()}
|
||||
* @param type
|
||||
* {@link DistributionSet#getType()}
|
||||
* @param moduleList
|
||||
* {@link DistributionSet#getModules()}
|
||||
*
|
||||
* @return {@link DistributionSet} object
|
||||
*/
|
||||
DistributionSet generateDistributionSet(String name, String version, String description, DistributionSetType type,
|
||||
Collection<SoftwareModule> moduleList);
|
||||
|
||||
/**
|
||||
* Generates an empty {@link DistributionSetMetadata} element without
|
||||
* persisting it.
|
||||
*
|
||||
* @return {@link DistributionSetMetadata} object
|
||||
*/
|
||||
DistributionSetMetadata generateDistributionSetMetadata();
|
||||
|
||||
/**
|
||||
* Generates an {@link DistributionSetMetadata} element without persisting
|
||||
* it.
|
||||
*
|
||||
* @param distributionSet
|
||||
* {@link DistributionSetMetadata#getDistributionSet()}
|
||||
* @param key
|
||||
* {@link DistributionSetMetadata#getKey()}
|
||||
* @param value
|
||||
* {@link DistributionSetMetadata#getValue()}
|
||||
*
|
||||
* @return {@link DistributionSetMetadata} object
|
||||
*/
|
||||
DistributionSetMetadata generateDistributionSetMetadata(DistributionSet distributionSet, String key, String value);
|
||||
|
||||
/**
|
||||
* Generates an empty {@link DistributionSetTag} without persisting it.
|
||||
*
|
||||
* @return {@link DistributionSetTag} object
|
||||
*/
|
||||
DistributionSetTag generateDistributionSetTag();
|
||||
|
||||
/**
|
||||
* Generates a {@link DistributionSetTag} without persisting it.
|
||||
*
|
||||
* @param name
|
||||
* of the tag
|
||||
* @return {@link DistributionSetTag} object
|
||||
*/
|
||||
DistributionSetTag generateDistributionSetTag(String name);
|
||||
|
||||
/**
|
||||
* Generates a {@link DistributionSetTag} without persisting it.
|
||||
*
|
||||
* @param name
|
||||
* of the tag
|
||||
* @param description
|
||||
* of the tag
|
||||
* @param colour
|
||||
* of the tag
|
||||
* @return {@link DistributionSetTag} object
|
||||
*/
|
||||
DistributionSetTag generateDistributionSetTag(String name, String description, String colour);
|
||||
|
||||
/**
|
||||
* Generates an empty {@link DistributionSetType} without persisting it.
|
||||
*
|
||||
* @return {@link DistributionSetType} object
|
||||
*/
|
||||
DistributionSetType generateDistributionSetType();
|
||||
|
||||
/**
|
||||
* Generates a {@link DistributionSetType} without persisting it.
|
||||
*
|
||||
* @param key
|
||||
* {@link DistributionSetType#getKey()}
|
||||
* @param name
|
||||
* {@link DistributionSetType#getName()}
|
||||
* @param description
|
||||
* {@link DistributionSetType#getDescription()}
|
||||
*
|
||||
* @return {@link DistributionSetType} object
|
||||
*/
|
||||
DistributionSetType generateDistributionSetType(String key, String name, String description);
|
||||
|
||||
/**
|
||||
* Generates an empty {@link Rollout} without persisting it.
|
||||
*
|
||||
* @return {@link Rollout} object
|
||||
*/
|
||||
Rollout generateRollout();
|
||||
|
||||
/**
|
||||
* Generates an empty {@link RolloutGroup} without persisting it.
|
||||
*
|
||||
* @return {@link RolloutGroup} object
|
||||
*/
|
||||
RolloutGroup generateRolloutGroup();
|
||||
|
||||
/**
|
||||
* Generates an empty {@link SoftwareModule} without persisting it.
|
||||
*
|
||||
* @return {@link SoftwareModule} object
|
||||
*/
|
||||
SoftwareModule generateSoftwareModule();
|
||||
|
||||
/**
|
||||
* Generates a {@link SoftwareModule} without persisting it.
|
||||
*
|
||||
* @param type
|
||||
* of the {@link SoftwareModule}
|
||||
* @param name
|
||||
* abstract name of the {@link SoftwareModule}
|
||||
* @param version
|
||||
* of the {@link SoftwareModule}
|
||||
* @param description
|
||||
* of the {@link SoftwareModule}
|
||||
* @param vendor
|
||||
* of the {@link SoftwareModule}
|
||||
*
|
||||
* @return {@link SoftwareModule} object
|
||||
*/
|
||||
SoftwareModule generateSoftwareModule(SoftwareModuleType type, String name, String version, String description,
|
||||
String vendor);
|
||||
|
||||
/**
|
||||
* Generates an empty {@link SoftwareModuleMetadata} pair without persisting
|
||||
* it.
|
||||
*
|
||||
* @return {@link SoftwareModuleMetadata} object
|
||||
*/
|
||||
SoftwareModuleMetadata generateSoftwareModuleMetadata();
|
||||
|
||||
/**
|
||||
* Generates a {@link SoftwareModuleMetadata} pair without persisting it.
|
||||
*
|
||||
* @param softwareModule
|
||||
* {@link SoftwareModuleMetadata#getSoftwareModule()}
|
||||
* @param key
|
||||
* {@link SoftwareModuleMetadata#getKey()}
|
||||
* @param value
|
||||
* {@link SoftwareModuleMetadata#getValue()}
|
||||
*
|
||||
* @return {@link SoftwareModuleMetadata} object
|
||||
*/
|
||||
SoftwareModuleMetadata generateSoftwareModuleMetadata(SoftwareModule softwareModule, String key, String value);
|
||||
|
||||
/**
|
||||
* Generates an empty {@link SoftwareModuleType} without persisting it.
|
||||
*
|
||||
* @return {@link SoftwareModuleType} object
|
||||
*/
|
||||
SoftwareModuleType generateSoftwareModuleType();
|
||||
|
||||
/**
|
||||
* Generates a {@link SoftwareModuleType} without persisting it.
|
||||
*
|
||||
* @param key
|
||||
* {@link SoftwareModuleType#getKey()}
|
||||
* @param name
|
||||
* {@link SoftwareModuleType#getName()}
|
||||
* @param description
|
||||
* {@link SoftwareModuleType#getDescription()}
|
||||
* @param maxAssignments
|
||||
* {@link SoftwareModuleType#getMaxAssignments()}
|
||||
*
|
||||
* @return {@link SoftwareModuleType} object
|
||||
*/
|
||||
SoftwareModuleType generateSoftwareModuleType(String key, String name, String description, int maxAssignments);
|
||||
|
||||
/**
|
||||
* Generates an empty {@link Target} without persisting it.
|
||||
*
|
||||
* @param controllerID
|
||||
* of the {@link Target}
|
||||
*
|
||||
* @return {@link Target} object
|
||||
*/
|
||||
Target generateTarget(@NotEmpty String controllerID);
|
||||
|
||||
/**
|
||||
* Generates an empty {@link TargetFilterQuery} without persisting it.
|
||||
*
|
||||
* @return {@link TargetFilterQuery} object
|
||||
*/
|
||||
TargetFilterQuery generateTargetFilterQuery();
|
||||
|
||||
/**
|
||||
* Generates an empty {@link TargetTag} without persisting it.
|
||||
*
|
||||
* @return {@link TargetTag} object
|
||||
*/
|
||||
TargetTag generateTargetTag();
|
||||
|
||||
/**
|
||||
* Generates a {@link TargetTag} without persisting it.
|
||||
*
|
||||
* @param name
|
||||
* of the tag
|
||||
* @return {@link TargetTag} object
|
||||
*/
|
||||
TargetTag generateTargetTag(String name);
|
||||
|
||||
/**
|
||||
* Generates a {@link TargetTag} without persisting it.
|
||||
*
|
||||
* @param name
|
||||
* of the tag
|
||||
* @param description
|
||||
* of the tag
|
||||
* @param colour
|
||||
* of the tag
|
||||
* @return {@link TargetTag} object
|
||||
*/
|
||||
TargetTag generateTargetTag(String name, String description, String colour);
|
||||
|
||||
}
|
||||
@@ -62,4 +62,31 @@ public final class OffsetBasedPageRequest extends PageRequest {
|
||||
return "OffsetBasedPageRequest [offset=" + offset + ", getPageSize()=" + getPageSize() + ", getPageNumber()="
|
||||
+ getPageNumber() + "]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = super.hashCode();
|
||||
result = prime * result + offset;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (!super.equals(obj)) {
|
||||
return false;
|
||||
}
|
||||
if (!(obj instanceof OffsetBasedPageRequest)) {
|
||||
return false;
|
||||
}
|
||||
final OffsetBasedPageRequest other = (OffsetBasedPageRequest) obj;
|
||||
if (offset != other.offset) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -150,11 +150,4 @@ public interface RolloutGroupManagement {
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ)
|
||||
RolloutGroup findRolloutGroupWithDetailedStatus(@NotNull Long rolloutGroupId);
|
||||
|
||||
/**
|
||||
* Generates an empty {@link RolloutGroup} without persisting it.
|
||||
*
|
||||
* @return {@link RolloutGroup} object
|
||||
*/
|
||||
RolloutGroup generateRolloutGroup();
|
||||
}
|
||||
@@ -341,11 +341,4 @@ public interface RolloutManagement {
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_WRITE)
|
||||
Rollout updateRollout(@NotNull Rollout rollout);
|
||||
|
||||
/**
|
||||
* Generates an empty {@link Rollout} without persisting it.
|
||||
*
|
||||
* @return {@link Rollout} object
|
||||
*/
|
||||
Rollout generateRollout();
|
||||
|
||||
}
|
||||
|
||||
@@ -483,50 +483,4 @@ public interface SoftwareManagement {
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY)
|
||||
SoftwareModuleType updateSoftwareModuleType(@NotNull SoftwareModuleType sm);
|
||||
|
||||
/**
|
||||
* Generates an empty {@link SoftwareModuleType} without persisting it.
|
||||
*
|
||||
* @return {@link SoftwareModuleType} object
|
||||
*/
|
||||
SoftwareModuleType generateSoftwareModuleType();
|
||||
|
||||
/**
|
||||
* Generates an empty {@link SoftwareModule} without persisting it.
|
||||
*
|
||||
* @return {@link SoftwareModule} object
|
||||
*/
|
||||
SoftwareModule generateSoftwareModule();
|
||||
|
||||
/**
|
||||
* Generates a {@link SoftwareModule} without persisting it.
|
||||
*
|
||||
* @param type
|
||||
* of the {@link SoftwareModule}
|
||||
* @param name
|
||||
* abstract name of the {@link SoftwareModule}
|
||||
* @param version
|
||||
* of the {@link SoftwareModule}
|
||||
* @param description
|
||||
* of the {@link SoftwareModule}
|
||||
* @param vendor
|
||||
* of the {@link SoftwareModule}
|
||||
*
|
||||
* @return {@link SoftwareModule} object
|
||||
*/
|
||||
SoftwareModule generateSoftwareModule(SoftwareModuleType type, String name, String version, String description,
|
||||
String vendor);
|
||||
|
||||
/**
|
||||
* Generates an empty {@link SoftwareModuleMetadata} pair without persisting
|
||||
* it.
|
||||
*
|
||||
* @return {@link SoftwareModuleMetadata} object
|
||||
*/
|
||||
SoftwareModuleMetadata generateSoftwareModuleMetadata();
|
||||
|
||||
SoftwareModuleMetadata generateSoftwareModuleMetadata(SoftwareModule softwareModule, String key, String value);
|
||||
|
||||
SoftwareModuleType generateSoftwareModuleType(final String key, final String name, final String description,
|
||||
final int maxAssignments);
|
||||
|
||||
}
|
||||
|
||||
@@ -13,6 +13,8 @@ import java.util.List;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetType;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
|
||||
import org.eclipse.hawkbit.repository.model.TenantMetaData;
|
||||
import org.eclipse.hawkbit.repository.report.model.SystemUsageReport;
|
||||
import org.eclipse.hawkbit.tenancy.TenantAware;
|
||||
@@ -39,7 +41,8 @@ public interface SystemManagement {
|
||||
* @param tenant
|
||||
* to delete
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_SYSTEM_ADMIN)
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_SYSTEM_ADMIN + SpringEvalExpressions.HAS_AUTH_OR
|
||||
+ SpringEvalExpressions.IS_SYSTEM_CODE)
|
||||
void deleteTenant(@NotNull String tenant);
|
||||
|
||||
/**
|
||||
@@ -69,7 +72,10 @@ public interface SystemManagement {
|
||||
KeyGenerator currentTenantKeyGenerator();
|
||||
|
||||
/**
|
||||
* Returns {@link TenantMetaData} of given and current tenant.
|
||||
* Returns {@link TenantMetaData} of given and current tenant. Creates for
|
||||
* new tenants also two {@link SoftwareModuleType} (os and app) and
|
||||
* {@link Constants#DEFAULT_DS_TYPES_IN_TENANT} {@link DistributionSetType}s
|
||||
* (os and os_app).
|
||||
*
|
||||
* DISCLAIMER: this variant is used during initial login (where the tenant
|
||||
* is not yet in the session). Please user {@link #getTenantMetadata()} for
|
||||
|
||||
@@ -245,62 +245,4 @@ public interface TagManagement {
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET)
|
||||
TargetTag updateTargetTag(@NotNull TargetTag targetTag);
|
||||
|
||||
/**
|
||||
* Generates an empty {@link TargetTag} without persisting it.
|
||||
*
|
||||
* @return {@link TargetTag} object
|
||||
*/
|
||||
TargetTag generateTargetTag();
|
||||
|
||||
/**
|
||||
* Generates an empty {@link DistributionSetTag} without persisting it.
|
||||
*
|
||||
* @return {@link DistributionSetTag} object
|
||||
*/
|
||||
DistributionSetTag generateDistributionSetTag();
|
||||
|
||||
/**
|
||||
* Generates a {@link TargetTag} without persisting it.
|
||||
*
|
||||
* @param name
|
||||
* of the tag
|
||||
* @param description
|
||||
* of the tag
|
||||
* @param colour
|
||||
* of the tag
|
||||
* @return {@link TargetTag} object
|
||||
*/
|
||||
TargetTag generateTargetTag(String name, String description, String colour);
|
||||
|
||||
/**
|
||||
* Generates a {@link TargetTag} without persisting it.
|
||||
*
|
||||
* @param name
|
||||
* of the tag
|
||||
* @return {@link TargetTag} object
|
||||
*/
|
||||
TargetTag generateTargetTag(String name);
|
||||
|
||||
/**
|
||||
* Generates a {@link DistributionSetTag} without persisting it.
|
||||
*
|
||||
* @param name
|
||||
* of the tag
|
||||
* @param description
|
||||
* of the tag
|
||||
* @param colour
|
||||
* of the tag
|
||||
* @return {@link DistributionSetTag} object
|
||||
*/
|
||||
DistributionSetTag generateDistributionSetTag(String name, String description, String colour);
|
||||
|
||||
/**
|
||||
* Generates a {@link DistributionSetTag} without persisting it.
|
||||
*
|
||||
* @param name
|
||||
* of the tag
|
||||
* @return {@link DistributionSetTag} object
|
||||
*/
|
||||
DistributionSetTag generateDistributionSetTag(String name);
|
||||
|
||||
}
|
||||
|
||||
@@ -95,11 +95,4 @@ public interface TargetFilterQueryManagement {
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET)
|
||||
TargetFilterQuery updateTargetFilterQuery(@NotNull TargetFilterQuery targetFilterQuery);
|
||||
|
||||
/**
|
||||
* Generates an empty {@link TargetFilterQuery} without persisting it.
|
||||
*
|
||||
* @return {@link TargetFilterQuery} object
|
||||
*/
|
||||
TargetFilterQuery generateTargetFilterQuery();
|
||||
}
|
||||
@@ -601,14 +601,4 @@ public interface TargetManagement {
|
||||
+ SpringEvalExpressions.IS_CONTROLLER)
|
||||
List<Target> updateTargets(@NotNull Collection<Target> targets);
|
||||
|
||||
/**
|
||||
* Generates an empty {@link Target} without persisting it.
|
||||
*
|
||||
* @param controllerID
|
||||
* of the {@link Target}
|
||||
*
|
||||
* @return {@link Target} object
|
||||
*/
|
||||
Target generateTarget(@NotEmpty String controllerID);
|
||||
|
||||
}
|
||||
@@ -16,6 +16,7 @@ import org.springframework.security.access.prepost.PreAuthorize;
|
||||
* Management service for statistics of a single tenant.
|
||||
*
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface TenantStatsManagement {
|
||||
|
||||
/**
|
||||
|
||||
29
hawkbit-repository/hawkbit-repository-core/pom.xml
Normal file
29
hawkbit-repository/hawkbit-repository-core/pom.xml
Normal file
@@ -0,0 +1,29 @@
|
||||
<!--
|
||||
|
||||
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
|
||||
|
||||
-->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.eclipse.hawkbit</groupId>
|
||||
<artifactId>hawkbit-repository</artifactId>
|
||||
<version>0.2.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>hawkbit-repository-core</artifactId>
|
||||
<name>hawkBit :: Repository Core Implementation Support</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.hawkbit</groupId>
|
||||
<artifactId>hawkbit-repository-api</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -52,19 +52,20 @@
|
||||
<artifactId>hawkbit-repository-api</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.hawkbit</groupId>
|
||||
<artifactId>hawkbit-repository-core</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.hawkbit</groupId>
|
||||
<artifactId>hawkbit-artifact-repository-mongo</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net._01001111</groupId>
|
||||
<artifactId>jlorem</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot</artifactId>
|
||||
@@ -96,6 +97,12 @@
|
||||
</dependency>
|
||||
|
||||
<!-- Test -->
|
||||
<dependency>
|
||||
<groupId>org.eclipse.hawkbit</groupId>
|
||||
<artifactId>hawkbit-repository-test</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.h2database</groupId>
|
||||
<artifactId>h2</artifactId>
|
||||
@@ -121,21 +128,11 @@
|
||||
<artifactId>allure-junit-adaptor</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<!-- <dependency> -->
|
||||
<!-- <groupId>org.springframework.data</groupId> -->
|
||||
<!-- <artifactId>spring-data-rest-webmvc</artifactId> -->
|
||||
<!-- <scope>test</scope> -->
|
||||
<!-- </dependency> -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.security</groupId>
|
||||
<artifactId>spring-security-aspects</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
@@ -150,12 +147,7 @@
|
||||
<groupId>org.easytesting</groupId>
|
||||
<artifactId>fest-assert</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>de.flapdoodle.embed</groupId>
|
||||
<artifactId>de.flapdoodle.embed.mongo</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.security</groupId>
|
||||
<artifactId>spring-security-config</artifactId>
|
||||
@@ -170,7 +162,6 @@
|
||||
<groupId>cz.jirutka.rsql</groupId>
|
||||
<artifactId>rsql-parser</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
59
hawkbit-repository/hawkbit-repository-test/pom.xml
Normal file
59
hawkbit-repository/hawkbit-repository-test/pom.xml
Normal file
@@ -0,0 +1,59 @@
|
||||
<!--
|
||||
|
||||
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
|
||||
|
||||
-->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.eclipse.hawkbit</groupId>
|
||||
<artifactId>hawkbit-repository</artifactId>
|
||||
<version>0.2.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>hawkbit-repository-test</artifactId>
|
||||
<name>hawkBit :: Repository Test Utilities</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.hawkbit</groupId>
|
||||
<artifactId>hawkbit-repository-api</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.hawkbit</groupId>
|
||||
<artifactId>hawkbit-repository-core</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.hawkbit</groupId>
|
||||
<artifactId>hawkbit-artifact-repository-mongo</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>de.flapdoodle.embed</groupId>
|
||||
<artifactId>de.flapdoodle.embed.mongo</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net._01001111</groupId>
|
||||
<artifactId>jlorem</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>2.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.security</groupId>
|
||||
<artifactId>spring-security-config</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -6,22 +6,15 @@
|
||||
* 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;
|
||||
package org.eclipse.hawkbit.repository.util;
|
||||
|
||||
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.Constants;
|
||||
import org.eclipse.hawkbit.repository.ControllerManagement;
|
||||
import org.eclipse.hawkbit.repository.DeploymentManagement;
|
||||
import org.eclipse.hawkbit.repository.DistributionSetManagement;
|
||||
import org.eclipse.hawkbit.repository.EntityFactory;
|
||||
import org.eclipse.hawkbit.repository.RolloutGroupManagement;
|
||||
import org.eclipse.hawkbit.repository.RolloutManagement;
|
||||
import org.eclipse.hawkbit.repository.SoftwareManagement;
|
||||
@@ -30,32 +23,13 @@ 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;
|
||||
@@ -63,13 +37,11 @@ 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;
|
||||
@@ -78,12 +50,10 @@ 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
|
||||
@@ -96,44 +66,16 @@ public abstract class AbstractIntegrationTest implements EnvironmentAware {
|
||||
|
||||
protected static final Pageable pageReq = new PageRequest(0, 400);
|
||||
|
||||
@PersistenceContext
|
||||
protected EntityManager entityManager;
|
||||
/**
|
||||
* Number of {@link DistributionSetType}s that exist in every test case. One
|
||||
* generated by using
|
||||
* {@link TestdataFactory#findOrCreateDefaultTestDsType()} and two
|
||||
* {@link SystemManagement#getTenantMetadata()};
|
||||
*/
|
||||
protected static final int DEFAULT_DS_TYPES = Constants.DEFAULT_DS_TYPES_IN_TENANT + 1;
|
||||
|
||||
@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;
|
||||
protected EntityFactory entityFactory;
|
||||
|
||||
@Autowired
|
||||
protected SoftwareManagement softwareManagement;
|
||||
@@ -159,15 +101,6 @@ public abstract class AbstractIntegrationTest implements EnvironmentAware {
|
||||
@Autowired
|
||||
protected ArtifactManagement artifactManagement;
|
||||
|
||||
@Autowired
|
||||
protected LocalArtifactRepository artifactRepository;
|
||||
|
||||
@Autowired
|
||||
protected TargetInfoRepository targetInfoRepository;
|
||||
|
||||
@Autowired
|
||||
protected GridFsOperations operations;
|
||||
|
||||
@Autowired
|
||||
protected WebApplicationContext context;
|
||||
|
||||
@@ -183,9 +116,6 @@ public abstract class AbstractIntegrationTest implements EnvironmentAware {
|
||||
@Autowired
|
||||
protected SystemManagement systemManagement;
|
||||
|
||||
@Autowired
|
||||
protected TenantAwareCacheManager cacheManager;
|
||||
|
||||
@Autowired
|
||||
protected TenantConfigurationManagement tenantConfigurationManagement;
|
||||
|
||||
@@ -195,19 +125,13 @@ public abstract class AbstractIntegrationTest implements EnvironmentAware {
|
||||
@Autowired
|
||||
protected RolloutGroupManagement rolloutGroupManagement;
|
||||
|
||||
@Autowired
|
||||
protected RolloutGroupRepository rolloutGroupRepository;
|
||||
|
||||
@Autowired
|
||||
protected RolloutRepository rolloutRepository;
|
||||
|
||||
@Autowired
|
||||
protected SystemSecurityContext systemSecurityContext;
|
||||
|
||||
protected MockMvc mvc;
|
||||
|
||||
@Autowired
|
||||
protected DatabaseCleanupUtil dbCleanupUtil;
|
||||
protected TestRepositoryManagement testRepositoryManagement;
|
||||
|
||||
protected MockMvc mvc;
|
||||
|
||||
protected SoftwareModuleType osType;
|
||||
protected SoftwareModuleType appType;
|
||||
@@ -215,13 +139,14 @@ public abstract class AbstractIntegrationTest implements EnvironmentAware {
|
||||
|
||||
protected DistributionSetType standardDsType;
|
||||
|
||||
@Autowired
|
||||
protected TestdataFactory testdataFactory;
|
||||
|
||||
@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;
|
||||
@@ -230,20 +155,29 @@ public abstract class AbstractIntegrationTest implements EnvironmentAware {
|
||||
@Before
|
||||
public void before() throws Exception {
|
||||
mvc = createMvcWebAppContext().build();
|
||||
final String description = "Updated description to have lastmodified available in tests";
|
||||
|
||||
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(() -> testdataFactory.findOrCreateSoftwareModuleType(TestdataFactory.SM_TYPE_OS));
|
||||
osType.setDescription(description);
|
||||
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(
|
||||
() -> testdataFactory.findOrCreateSoftwareModuleType(TestdataFactory.SM_TYPE_APP, Integer.MAX_VALUE));
|
||||
appType.setDescription(description);
|
||||
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(() -> testdataFactory.findOrCreateSoftwareModuleType(TestdataFactory.SM_TYPE_RT));
|
||||
runtimeType.setDescription(description);
|
||||
runtimeType = securityRule.runAsPrivileged(() -> softwareManagement.updateSoftwareModuleType(runtimeType));
|
||||
|
||||
standardDsType = securityRule.runAsPrivileged(() -> testdataFactory.findOrCreateDefaultTestDsType());
|
||||
}
|
||||
|
||||
@After
|
||||
public void after() {
|
||||
testRepositoryManagement.clearTestRepository();
|
||||
}
|
||||
|
||||
protected DefaultMockMvcBuilder createMvcWebAppContext() {
|
||||
@@ -254,59 +188,6 @@ public abstract class AbstractIntegrationTest implements EnvironmentAware {
|
||||
"/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
|
||||
@@ -6,7 +6,7 @@
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa;
|
||||
package org.eclipse.hawkbit.repository.util;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.UnknownHostException;
|
||||
@@ -15,7 +15,9 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.mongodb.core.query.Query;
|
||||
import org.springframework.data.mongodb.gridfs.GridFsOperations;
|
||||
|
||||
import de.flapdoodle.embed.mongo.Command;
|
||||
import de.flapdoodle.embed.mongo.MongodExecutable;
|
||||
@@ -38,10 +40,14 @@ import de.flapdoodle.embed.process.runtime.Network;
|
||||
*
|
||||
*/
|
||||
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;
|
||||
|
||||
@Autowired
|
||||
protected GridFsOperations operations;
|
||||
|
||||
@BeforeClass
|
||||
public static void setupMongo() throws UnknownHostException, IOException {
|
||||
mongoLease.incrementAndGet();
|
||||
@@ -67,8 +73,8 @@ public abstract class AbstractIntegrationTestWithMongoDB extends AbstractIntegra
|
||||
new ArtifactStoreBuilder().defaults(command)
|
||||
.download(new DownloadConfigBuilder().defaultsForCommand(command)
|
||||
.proxyFactory(new HttpProxyFactory(
|
||||
System.getProperty("http.proxyHost").trim(),
|
||||
Integer.valueOf(System.getProperty("http.proxyPort"))))));
|
||||
System.getProperty("http.proxyHost").trim(), Integer
|
||||
.valueOf(System.getProperty("http.proxyPort"))))));
|
||||
}
|
||||
|
||||
final IMongodConfig mongodConfig = new MongodConfigBuilder().version(version)
|
||||
@@ -86,7 +92,7 @@ public abstract class AbstractIntegrationTestWithMongoDB extends AbstractIntegra
|
||||
operations.delete(new Query());
|
||||
}
|
||||
|
||||
public void internalShutDownMongo() {
|
||||
public static void internalShutDownMongo() {
|
||||
if (mongodExecutable != null && mongoLease.decrementAndGet() <= 0) {
|
||||
mongodExecutable.stop();
|
||||
mongodExecutable = null;
|
||||
@@ -6,7 +6,7 @@
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa;
|
||||
package org.eclipse.hawkbit.repository.util;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.InetSocketAddress;
|
||||
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* 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.util;
|
||||
|
||||
/**
|
||||
* Repository support for tests.
|
||||
*
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface TestRepositoryManagement {
|
||||
/**
|
||||
* Empty the test repository.
|
||||
*/
|
||||
void clearTestRepository();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,737 @@
|
||||
/**
|
||||
* 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.util;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.Charset;
|
||||
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.DeploymentManagement;
|
||||
import org.eclipse.hawkbit.repository.DistributionSetManagement;
|
||||
import org.eclipse.hawkbit.repository.EntityFactory;
|
||||
import org.eclipse.hawkbit.repository.SoftwareManagement;
|
||||
import org.eclipse.hawkbit.repository.TagManagement;
|
||||
import org.eclipse.hawkbit.repository.TargetManagement;
|
||||
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.Artifact;
|
||||
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.LocalArtifact;
|
||||
import org.eclipse.hawkbit.repository.model.NamedEntity;
|
||||
import org.eclipse.hawkbit.repository.model.NamedVersionedEntity;
|
||||
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.beans.factory.annotation.Autowired;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import net._01001111.text.LoremIpsum;
|
||||
|
||||
/**
|
||||
* Data generator utility for tests.
|
||||
*/
|
||||
public class TestdataFactory {
|
||||
private static final LoremIpsum LOREM = new LoremIpsum();
|
||||
|
||||
/**
|
||||
* default {@link Target#getControllerId()}.
|
||||
*/
|
||||
public static final String DEFAULT_CONTROLLER_ID = "targetExist";
|
||||
|
||||
/**
|
||||
* Default {@link SoftwareModule#getVendor()}.
|
||||
*/
|
||||
public static final String DEFAULT_VENDOR = "Vendor Limited, California";
|
||||
|
||||
/**
|
||||
* Default {@link NamedVersionedEntity#getVersion()}.
|
||||
*/
|
||||
public static final String DEFAULT_VERSION = "1.0";
|
||||
|
||||
/**
|
||||
* Default {@link NamedEntity#getDescription()}.
|
||||
*/
|
||||
public static final String DEFAULT_DESCRIPTION = "Desc: " + LOREM.words(10);
|
||||
|
||||
/**
|
||||
* Key of test default {@link DistributionSetType}.
|
||||
*/
|
||||
public static final String DS_TYPE_DEFAULT = "test_default_ds_type";
|
||||
|
||||
/**
|
||||
* Key of test "os" {@link SoftwareModuleType} -> mandatory firmware in
|
||||
* {@link #DS_TYPE_DEFAULT}.
|
||||
*/
|
||||
public static final String SM_TYPE_OS = "os";
|
||||
|
||||
/**
|
||||
* Key of test "runtime" {@link SoftwareModuleType} -> optional firmware in
|
||||
* {@link #DS_TYPE_DEFAULT}.
|
||||
*/
|
||||
public static final String SM_TYPE_RT = "runtime";
|
||||
|
||||
/**
|
||||
* Key of test "application" {@link SoftwareModuleType} -> optional software
|
||||
* in {@link #DS_TYPE_DEFAULT}.
|
||||
*/
|
||||
public static final String SM_TYPE_APP = "application";
|
||||
|
||||
@Autowired
|
||||
private ControllerManagement controllerManagament;
|
||||
|
||||
@Autowired
|
||||
private SoftwareManagement softwareManagement;
|
||||
|
||||
@Autowired
|
||||
private DistributionSetManagement distributionSetManagement;
|
||||
|
||||
@Autowired
|
||||
private TargetManagement targetManagement;
|
||||
|
||||
@Autowired
|
||||
private DeploymentManagement deploymentManagement;
|
||||
|
||||
@Autowired
|
||||
private TagManagement tagManagement;
|
||||
|
||||
@Autowired
|
||||
private EntityFactory entityFactory;
|
||||
|
||||
@Autowired
|
||||
private ArtifactManagement artifactManagement;
|
||||
|
||||
/**
|
||||
* Creates {@link DistributionSet} in repository including three
|
||||
* {@link SoftwareModule}s of types {@link #SM_TYPE_OS}, {@link #SM_TYPE_RT}
|
||||
* , {@link #SM_TYPE_APP} with {@link #DEFAULT_VERSION} and
|
||||
* {@link DistributionSet#isRequiredMigrationStep()} <code>false</code>.
|
||||
*
|
||||
* @param prefix
|
||||
* for {@link SoftwareModule}s and {@link DistributionSet}s name,
|
||||
* vendor and description.
|
||||
*
|
||||
* @return {@link DistributionSet} entity.
|
||||
*/
|
||||
public DistributionSet createDistributionSet(final String prefix) {
|
||||
return createDistributionSet(prefix, DEFAULT_VERSION, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates {@link DistributionSet} in repository including three
|
||||
* {@link SoftwareModule}s of types {@link #SM_TYPE_OS}, {@link #SM_TYPE_RT}
|
||||
* , {@link #SM_TYPE_APP} with {@link #DEFAULT_VERSION}.
|
||||
*
|
||||
* @param prefix
|
||||
* for {@link SoftwareModule}s and {@link DistributionSet}s name,
|
||||
* vendor and description.
|
||||
* @param isRequiredMigrationStep
|
||||
* for {@link DistributionSet#isRequiredMigrationStep()}
|
||||
*
|
||||
* @return {@link DistributionSet} entity.
|
||||
*/
|
||||
public DistributionSet createDistributionSet(final String prefix, final boolean isRequiredMigrationStep) {
|
||||
return createDistributionSet(prefix, DEFAULT_VERSION, isRequiredMigrationStep);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates {@link DistributionSet} in repository including three
|
||||
* {@link SoftwareModule}s of types {@link #SM_TYPE_OS}, {@link #SM_TYPE_RT}
|
||||
* , {@link #SM_TYPE_APP} with {@link #DEFAULT_VERSION} and
|
||||
* {@link DistributionSet#isRequiredMigrationStep()} <code>false</code>.
|
||||
*
|
||||
* @param prefix
|
||||
* for {@link SoftwareModule}s and {@link DistributionSet}s name,
|
||||
* vendor and description.
|
||||
* @param tags
|
||||
* {@link DistributionSet#getTags()}
|
||||
*
|
||||
* @return {@link DistributionSet} entity.
|
||||
*/
|
||||
public DistributionSet createDistributionSet(final String prefix, final Collection<DistributionSetTag> tags) {
|
||||
return createDistributionSet(prefix, DEFAULT_VERSION, tags);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates {@link DistributionSet} in repository including three
|
||||
* {@link SoftwareModule}s of types {@link #SM_TYPE_OS}, {@link #SM_TYPE_RT}
|
||||
* , {@link #SM_TYPE_APP}.
|
||||
*
|
||||
* @param prefix
|
||||
* for {@link SoftwareModule}s and {@link DistributionSet}s name,
|
||||
* vendor and description.
|
||||
* @param version
|
||||
* {@link DistributionSet#getVersion()} and
|
||||
* {@link SoftwareModule#getVersion()} extended by a random
|
||||
* number.
|
||||
* @param isRequiredMigrationStep
|
||||
* for {@link DistributionSet#isRequiredMigrationStep()}
|
||||
*
|
||||
* @return {@link DistributionSet} entity.
|
||||
*/
|
||||
public DistributionSet createDistributionSet(final String prefix, final String version,
|
||||
final boolean isRequiredMigrationStep) {
|
||||
|
||||
final SoftwareModule appMod = softwareManagement.createSoftwareModule(entityFactory.generateSoftwareModule(
|
||||
findOrCreateSoftwareModuleType(SM_TYPE_APP, Integer.MAX_VALUE), prefix + SM_TYPE_APP,
|
||||
version + "." + new Random().nextInt(100), LOREM.words(20), prefix + " vendor Limited, California"));
|
||||
final SoftwareModule runtimeMod = softwareManagement
|
||||
.createSoftwareModule(entityFactory.generateSoftwareModule(findOrCreateSoftwareModuleType(SM_TYPE_RT),
|
||||
prefix + "app runtime", version + "." + new Random().nextInt(100), LOREM.words(20),
|
||||
prefix + " vendor GmbH, Stuttgart, Germany"));
|
||||
final SoftwareModule osMod = softwareManagement
|
||||
.createSoftwareModule(entityFactory.generateSoftwareModule(findOrCreateSoftwareModuleType(SM_TYPE_OS),
|
||||
prefix + " Firmware", version + "." + new Random().nextInt(100), LOREM.words(20),
|
||||
prefix + " vendor Limited Inc, California"));
|
||||
|
||||
return distributionSetManagement
|
||||
.createDistributionSet(generateDistributionSet(prefix != null && prefix.length() > 0 ? prefix : "DS",
|
||||
version, findOrCreateDefaultTestDsType(), Lists.newArrayList(osMod, runtimeMod, appMod))
|
||||
.setRequiredMigrationStep(isRequiredMigrationStep));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates {@link DistributionSet} in repository including three
|
||||
* {@link SoftwareModule}s of types {@link #SM_TYPE_OS}, {@link #SM_TYPE_RT}
|
||||
* , {@link #SM_TYPE_APP}.
|
||||
*
|
||||
* @param prefix
|
||||
* for {@link SoftwareModule}s and {@link DistributionSet}s name,
|
||||
* vendor and description.
|
||||
* @param version
|
||||
* {@link DistributionSet#getVersion()} and
|
||||
* {@link SoftwareModule#getVersion()} extended by a random
|
||||
* number.
|
||||
* @param tags
|
||||
* {@link DistributionSet#getTags()}
|
||||
*
|
||||
* @return {@link DistributionSet} entity.
|
||||
*/
|
||||
public DistributionSet createDistributionSet(final String prefix, final String version,
|
||||
final Collection<DistributionSetTag> tags) {
|
||||
|
||||
final DistributionSet set = createDistributionSet(prefix, version, false);
|
||||
|
||||
final List<DistributionSet> sets = new ArrayList<>();
|
||||
sets.add(set);
|
||||
|
||||
tags.forEach(tag -> distributionSetManagement.toggleTagAssignment(sets, tag));
|
||||
|
||||
return distributionSetManagement.findDistributionSetById(set.getId());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates {@link DistributionSet}s in repository including three
|
||||
* {@link SoftwareModule}s of types {@link #SM_TYPE_OS}, {@link #SM_TYPE_RT}
|
||||
* , {@link #SM_TYPE_APP} with {@link #DEFAULT_VERSION} followed by an
|
||||
* iterative number and {@link DistributionSet#isRequiredMigrationStep()}
|
||||
* <code>false</code>.
|
||||
*
|
||||
* @param number
|
||||
* of {@link DistributionSet}s to create
|
||||
*
|
||||
* @return {@link List} of {@link DistributionSet} entities
|
||||
*/
|
||||
public List<DistributionSet> createDistributionSets(final int number) {
|
||||
|
||||
return createDistributionSets("", number);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates {@link DistributionSet}s in repository including three
|
||||
* {@link SoftwareModule}s of types {@link #SM_TYPE_OS}, {@link #SM_TYPE_RT}
|
||||
* , {@link #SM_TYPE_APP} with {@link #DEFAULT_VERSION} followed by an
|
||||
* iterative number and {@link DistributionSet#isRequiredMigrationStep()}
|
||||
* <code>false</code>.
|
||||
*
|
||||
* @param prefix
|
||||
* for {@link SoftwareModule}s and {@link DistributionSet}s name,
|
||||
* vendor and description.
|
||||
* @param number
|
||||
* of {@link DistributionSet}s to create
|
||||
*
|
||||
* @return {@link List} of {@link DistributionSet} entities
|
||||
*/
|
||||
public List<DistributionSet> createDistributionSets(final String prefix, final int number) {
|
||||
|
||||
final List<DistributionSet> sets = new ArrayList<>();
|
||||
for (int i = 0; i < number; i++) {
|
||||
sets.add(createDistributionSet(prefix, DEFAULT_VERSION + "." + i, false));
|
||||
}
|
||||
|
||||
return sets;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates {@link DistributionSet}s in repository with
|
||||
* {@link #DEFAULT_DESCRIPTION} and
|
||||
* {@link DistributionSet#isRequiredMigrationStep()} <code>false</code>.
|
||||
*
|
||||
* @param name
|
||||
* {@link DistributionSet#getName()}
|
||||
* @param version
|
||||
* {@link DistributionSet#getVersion()}
|
||||
*
|
||||
* @return {@link DistributionSet} entity
|
||||
*/
|
||||
public DistributionSet createDistributionSetWithNoSoftwareModules(final String name, final String version) {
|
||||
|
||||
final DistributionSet dis = entityFactory.generateDistributionSet();
|
||||
dis.setName(name);
|
||||
dis.setVersion(version);
|
||||
dis.setDescription(DEFAULT_DESCRIPTION);
|
||||
dis.setType(findOrCreateDefaultTestDsType());
|
||||
return distributionSetManagement.createDistributionSet(dis);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates {@link LocalArtifact}s for given {@link SoftwareModule} with a
|
||||
* small text payload.
|
||||
*
|
||||
* @param moduleId
|
||||
* the {@link Artifact}s belong to.
|
||||
*
|
||||
* @return {@link LocalArtifact} entity.
|
||||
*/
|
||||
public List<LocalArtifact> createLocalArtifacts(final Long moduleId) {
|
||||
final List<LocalArtifact> artifacts = new ArrayList<>();
|
||||
for (int i = 0; i < 3; i++) {
|
||||
final InputStream stubInputStream = IOUtils.toInputStream("some test data" + i, Charset.forName("UTF-8"));
|
||||
artifacts.add(artifactManagement.createLocalArtifact(stubInputStream, moduleId, "filename" + i, false));
|
||||
|
||||
}
|
||||
|
||||
return artifacts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates {@link SoftwareModule} with {@link #DEFAULT_VENDOR} and
|
||||
* {@link #DEFAULT_VERSION} and random generated
|
||||
* {@link Target#getDescription()} in the repository.
|
||||
*
|
||||
* @param typeKey
|
||||
* of the {@link SoftwareModuleType}
|
||||
*
|
||||
* @return persisted {@link SoftwareModule}.
|
||||
*/
|
||||
public SoftwareModule createSoftwareModule(final String typeKey) {
|
||||
return softwareManagement.createSoftwareModule(entityFactory.generateSoftwareModule(
|
||||
findOrCreateSoftwareModuleType(typeKey), typeKey, DEFAULT_VERSION, LOREM.words(10), DEFAULT_VENDOR));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return persisted {@link Target} with {@link #DEFAULT_CONTROLLER_ID}.
|
||||
*/
|
||||
public Target createTarget() {
|
||||
return targetManagement.createTarget(entityFactory.generateTarget(DEFAULT_CONTROLLER_ID));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates {@link DistributionSet}s in repository including three
|
||||
* {@link SoftwareModule}s of types {@link #SM_TYPE_OS}, {@link #SM_TYPE_RT}
|
||||
* , {@link #SM_TYPE_APP} with {@link #DEFAULT_VERSION} followed by an
|
||||
* iterative number and {@link DistributionSet#isRequiredMigrationStep()}
|
||||
* <code>false</code>.
|
||||
*
|
||||
* @return persisted {@link DistributionSet}.
|
||||
*/
|
||||
public DistributionSet createTestDistributionSet() {
|
||||
DistributionSet set = createDistributionSet("");
|
||||
set.setVersion(DEFAULT_VERSION);
|
||||
set = distributionSetManagement.updateDistributionSet(set);
|
||||
|
||||
set.getModules().forEach(module -> {
|
||||
module.setDescription("Updated " + DEFAULT_DESCRIPTION);
|
||||
softwareManagement.updateSoftwareModule(module);
|
||||
});
|
||||
|
||||
// load also lazy stuff
|
||||
set = distributionSetManagement.findDistributionSetByIdWithDetails(set.getId());
|
||||
|
||||
return set;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {@link DistributionSetType} with key {@link #DS_TYPE_DEFAULT} and
|
||||
* {@link SoftwareModuleType}s {@link #SM_TYPE_OS},
|
||||
* {@link #SM_TYPE_RT} , {@link #SM_TYPE_APP}.
|
||||
*/
|
||||
public DistributionSetType findOrCreateDefaultTestDsType() {
|
||||
final List<SoftwareModuleType> mand = new ArrayList<>();
|
||||
mand.add(findOrCreateSoftwareModuleType(SM_TYPE_OS));
|
||||
|
||||
final List<SoftwareModuleType> opt = new ArrayList<>();
|
||||
opt.add(findOrCreateSoftwareModuleType(SM_TYPE_APP, Integer.MAX_VALUE));
|
||||
opt.add(findOrCreateSoftwareModuleType(SM_TYPE_RT));
|
||||
|
||||
return findOrCreateDistributionSetType(DS_TYPE_DEFAULT, "OS (FW) mandatory, runtime (FW) and app (SW) optional",
|
||||
mand, opt);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates {@link DistributionSetType} in repository.
|
||||
*
|
||||
* @param dsTypeKey
|
||||
* {@link DistributionSetType#getKey()}
|
||||
* @param dsTypeName
|
||||
* {@link DistributionSetType#getName()}
|
||||
*
|
||||
* @return persisted {@link DistributionSetType}
|
||||
*/
|
||||
public DistributionSetType findOrCreateDistributionSetType(final String dsTypeKey, final String dsTypeName) {
|
||||
final DistributionSetType findDistributionSetTypeByname = distributionSetManagement
|
||||
.findDistributionSetTypeByKey(dsTypeKey);
|
||||
|
||||
if (findDistributionSetTypeByname != null) {
|
||||
return findDistributionSetTypeByname;
|
||||
}
|
||||
|
||||
final DistributionSetType type = entityFactory.generateDistributionSetType(dsTypeKey, dsTypeName,
|
||||
LOREM.words(10));
|
||||
|
||||
return distributionSetManagement.createDistributionSetType(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds {@link DistributionSetType} in repository with given
|
||||
* {@link DistributionSetType#getKey()} or creates if it does not exist yet.
|
||||
*
|
||||
* @param dsTypeKey
|
||||
* {@link DistributionSetType#getKey()}
|
||||
* @param dsTypeName
|
||||
* {@link DistributionSetType#getName()}
|
||||
* @param mandatory
|
||||
* {@link DistributionSetType#getMandatoryModuleTypes()}
|
||||
* @param optional
|
||||
* {@link DistributionSetType#getOptionalModuleTypes()}
|
||||
*
|
||||
* @return persisted {@link DistributionSetType}
|
||||
*/
|
||||
public DistributionSetType findOrCreateDistributionSetType(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 = entityFactory.generateDistributionSetType(dsTypeKey, dsTypeName,
|
||||
LOREM.words(10));
|
||||
mandatory.forEach(type::addMandatoryModuleType);
|
||||
optional.forEach(type::addOptionalModuleType);
|
||||
|
||||
return distributionSetManagement.createDistributionSetType(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds {@link SoftwareModuleType} in repository with given
|
||||
* {@link SoftwareModuleType#getKey()} or creates if it does not exist yet
|
||||
* with {@link SoftwareModuleType#getMaxAssignments()} = 1.
|
||||
*
|
||||
* @param key
|
||||
* {@link SoftwareModuleType#getKey()}
|
||||
*
|
||||
* @return persisted {@link SoftwareModuleType}
|
||||
*/
|
||||
public SoftwareModuleType findOrCreateSoftwareModuleType(final String key) {
|
||||
return findOrCreateSoftwareModuleType(key, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds {@link SoftwareModuleType} in repository with given
|
||||
* {@link SoftwareModuleType#getKey()} or creates if it does not exist yet.
|
||||
*
|
||||
* @param key
|
||||
* {@link SoftwareModuleType#getKey()}
|
||||
* @param maxAssignments
|
||||
* {@link SoftwareModuleType#getMaxAssignments()}
|
||||
*
|
||||
* @return persisted {@link SoftwareModuleType}
|
||||
*/
|
||||
public SoftwareModuleType findOrCreateSoftwareModuleType(final String key, final int maxAssignments) {
|
||||
final SoftwareModuleType findSoftwareModuleTypeByKey = softwareManagement.findSoftwareModuleTypeByKey(key);
|
||||
if (findSoftwareModuleTypeByKey != null) {
|
||||
return findSoftwareModuleTypeByKey;
|
||||
}
|
||||
return softwareManagement.createSoftwareModuleType(
|
||||
entityFactory.generateSoftwareModuleType(key, key, LOREM.words(10), maxAssignments));
|
||||
}
|
||||
|
||||
/**
|
||||
* builder method for creating a {@link DistributionSet}.
|
||||
*
|
||||
* @param name
|
||||
* {@link DistributionSet#getName()}
|
||||
* @param version
|
||||
* {@link DistributionSet#getVersion()}
|
||||
* @param type
|
||||
* {@link DistributionSet#getType()}
|
||||
* @param modules
|
||||
* {@link DistributionSet#getModules()}
|
||||
*
|
||||
* @return the created {@link DistributionSet}
|
||||
*/
|
||||
public DistributionSet generateDistributionSet(final String name, final String version,
|
||||
final DistributionSetType type, final Collection<SoftwareModule> modules) {
|
||||
final DistributionSet distributionSet = entityFactory.generateDistributionSet(name, version, null, type,
|
||||
modules);
|
||||
distributionSet.setDescription(LOREM.words(10));
|
||||
return distributionSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates {@link DistributionSetTag}s in repository.
|
||||
*
|
||||
* @param number
|
||||
* of {@link DistributionSetTag}s
|
||||
*
|
||||
* @return the persisted {@link DistributionSetTag}s
|
||||
*/
|
||||
public List<DistributionSetTag> createDistributionSetTags(final int number) {
|
||||
final List<DistributionSetTag> result = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i < number; i++) {
|
||||
result.add(entityFactory.generateDistributionSetTag("tag" + i, "tagdesc" + i, String.valueOf(i)));
|
||||
}
|
||||
|
||||
return tagManagement.createDistributionSetTags(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 Target generateTarget(final String ctrlID, final String description) {
|
||||
return generateTarget(ctrlID, description, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a single {@link Target} from the given parameters.
|
||||
*
|
||||
* @param ctrlID
|
||||
* controllerID
|
||||
* @param description
|
||||
* the description of the target
|
||||
* @param tags
|
||||
* assigned {@link TargetTag}s
|
||||
* @return the generated {@link Target}
|
||||
*/
|
||||
private Target generateTarget(final String ctrlID, final String description, final TargetTag[] tags) {
|
||||
final Target target = entityFactory.generateTarget(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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates {@link Target}s in repository and with
|
||||
* {@link #DEFAULT_CONTROLLER_ID} as prefix for
|
||||
* {@link Target#getControllerId()}.
|
||||
*
|
||||
* @param number
|
||||
* of {@link Target}s to create
|
||||
*
|
||||
* @return {@link List} of {@link Target} entities
|
||||
*/
|
||||
public List<Target> createTargets(final int number) {
|
||||
return targetManagement.createTargets(generateTargets(0, number, DEFAULT_CONTROLLER_ID));
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds {@link Target} objects with given prefix for
|
||||
* {@link Target#getControllerId()} followed by a number suffix.
|
||||
*
|
||||
* @param start
|
||||
* value for the controllerId suffix
|
||||
* @param numberOfTargets
|
||||
* of {@link Target}s to generate
|
||||
* @param controllerIdPrefix
|
||||
* for {@link Target#getControllerId()} generation.
|
||||
* @return list of {@link Target} objects
|
||||
*/
|
||||
private List<Target> generateTargets(final int start, final int numberOfTargets, final String controllerIdPrefix) {
|
||||
final List<Target> targets = new ArrayList<>();
|
||||
for (int i = start; i < start + numberOfTargets; i++) {
|
||||
targets.add(entityFactory.generateTarget(controllerIdPrefix + i));
|
||||
}
|
||||
|
||||
return targets;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds {@link Target} objects with given prefix for
|
||||
* {@link Target#getControllerId()} followed by a number suffix starting
|
||||
* with 0.
|
||||
*
|
||||
* @param numberOfTargets
|
||||
* of {@link Target}s to generate
|
||||
* @param controllerIdPrefix
|
||||
* for {@link Target#getControllerId()} generation.
|
||||
* @return list of {@link Target} objects
|
||||
*/
|
||||
public List<Target> generateTargets(final int numberOfTargets, final String controllerIdPrefix) {
|
||||
return generateTargets(0, numberOfTargets, controllerIdPrefix);
|
||||
}
|
||||
|
||||
/**
|
||||
* builds a set of {@link Target} fixtures from the given parameters.
|
||||
*
|
||||
* @param numberOfTargets
|
||||
* number of targets to create
|
||||
* @param controllerIdPrefix
|
||||
* prefix used for the controller ID
|
||||
* @param descriptionPrefix
|
||||
* prefix used for the description
|
||||
* @return set of {@link Target}
|
||||
*/
|
||||
public List<Target> generateTargets(final int numberOfTargets, final String controllerIdPrefix,
|
||||
final String descriptionPrefix) {
|
||||
return generateTargets(numberOfTargets, controllerIdPrefix, 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 controllerIdPrefix
|
||||
* prefix of the controllerID which is concatenated with the
|
||||
* number of the target. Randomly generated if <code>null</code>.
|
||||
* @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
|
||||
*/
|
||||
private List<Target> generateTargets(final int noOfTgts, final String controllerIdPrefix,
|
||||
final String descriptionPrefix, final TargetTag[] tags) {
|
||||
final List<Target> list = new ArrayList<>();
|
||||
for (int i = 0; i < noOfTgts; i++) {
|
||||
String ctrlID = controllerIdPrefix;
|
||||
if (Strings.isNullOrEmpty(ctrlID)) {
|
||||
ctrlID = UUID.randomUUID().toString();
|
||||
}
|
||||
ctrlID = String.format("%s-%05d", ctrlID, i);
|
||||
|
||||
final String description = descriptionPrefix + DEFAULT_DESCRIPTION;
|
||||
|
||||
final Target target = generateTarget(ctrlID, description, tags);
|
||||
list.add(target);
|
||||
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates {@link TargetTag}s.
|
||||
*
|
||||
* @param number
|
||||
* of {@link TargetTag}s to generate.
|
||||
*
|
||||
* @return generated {@link TargetTag}s.
|
||||
*/
|
||||
public List<TargetTag> generateTargetTags(final int number) {
|
||||
final List<TargetTag> result = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i < number; i++) {
|
||||
result.add(entityFactory.generateTargetTag("tag" + i, "tagdesc" + i, String.valueOf(i)));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a set of {@link TargetTag}s.
|
||||
*
|
||||
* @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 List<TargetTag> generateTargetTags(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 = entityFactory.generateTargetTag(tagName);
|
||||
list.add(targetTag);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
private Action sendUpdateActionStatusToTarget(final Status status, final Action updActA, final String... msgs) {
|
||||
updActA.setStatus(status);
|
||||
|
||||
final ActionStatus statusMessages = entityFactory.generateActionStatus();
|
||||
statusMessages.setAction(updActA);
|
||||
statusMessages.setOccurredAt(System.currentTimeMillis());
|
||||
statusMessages.setStatus(status);
|
||||
for (final String msg : msgs) {
|
||||
statusMessages.addMessage(msg);
|
||||
}
|
||||
|
||||
return controllerManagament.addUpdateActionStatus(statusMessages);
|
||||
}
|
||||
|
||||
/**
|
||||
* Append {@link ActionStatus} to all {@link Action}s of given
|
||||
* {@link Target}s.
|
||||
*
|
||||
* @param targets
|
||||
* to add {@link ActionStatus}
|
||||
* @param status
|
||||
* to add
|
||||
* @param msgs
|
||||
* to add
|
||||
*
|
||||
* @return updated {@link Action}.
|
||||
*/
|
||||
public List<Action> sendUpdateActionStatusToTargets(final Collection<Target> targets, final Status status,
|
||||
final String... msgs) {
|
||||
final List<Action> result = new ArrayList<>();
|
||||
for (final Target target : targets) {
|
||||
final List<Action> findByTarget = deploymentManagement.findActionsByTarget(target);
|
||||
for (final Action action : findByTarget) {
|
||||
result.add(sendUpdateActionStatusToTarget(status, action, msgs));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa;
|
||||
package org.eclipse.hawkbit.repository.util;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Field;
|
||||
@@ -6,7 +6,7 @@
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa;
|
||||
package org.eclipse.hawkbit.repository.util;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Inherited;
|
||||
@@ -23,6 +23,8 @@
|
||||
<modules>
|
||||
<module>hawkbit-repository-jpa</module>
|
||||
<module>hawkbit-repository-api</module>
|
||||
<module>hawkbit-repository-test</module>
|
||||
<module>hawkbit-repository-core</module>
|
||||
</modules>
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user