Remove swagger and minor feature extensions and bug fixes
- Various Bug fixes and improvements - Management API extended - Swagger removed - Guava Upgraded to 19
This commit is contained in:
0
hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/MockMvcResultPrinter.java
Executable file → Normal file
0
hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/MockMvcResultPrinter.java
Executable file → Normal file
0
hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/controller/ArtifactDownloadTest.java
Executable file → Normal file
0
hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/controller/ArtifactDownloadTest.java
Executable file → Normal file
0
hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/controller/CancelActionTest.java
Executable file → Normal file
0
hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/controller/CancelActionTest.java
Executable file → Normal file
0
hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/controller/ConfigDataTest.java
Executable file → Normal file
0
hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/controller/ConfigDataTest.java
Executable file → Normal file
65
hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/controller/DeploymentBaseTest.java
Executable file → Normal file
65
hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/controller/DeploymentBaseTest.java
Executable file → Normal file
@@ -57,8 +57,8 @@ import ru.yandex.qatools.allure.annotations.Stories;
|
||||
public class DeploymentBaseTest extends AbstractIntegrationTestWithMongoDB {
|
||||
|
||||
@Test()
|
||||
@Description("Ensures that artifact not found, when softare module not exists ")
|
||||
public void testArtifactsNotFound() throws Exception {
|
||||
@Description("Ensures that artifacts are not found, when softare module does not exists.")
|
||||
public void artifactsNotFound() throws Exception {
|
||||
final Target target = TestDataUtil.createTarget(targetManagement);
|
||||
final Long softwareModuleIdNotExist = 1l;
|
||||
mvc.perform(get("/{tenant}/controller/v1/{targetNotExist}/softwaremodules/{softwareModuleId}/artifacts",
|
||||
@@ -67,8 +67,8 @@ public class DeploymentBaseTest extends AbstractIntegrationTestWithMongoDB {
|
||||
}
|
||||
|
||||
@Test()
|
||||
@Description("Ensures that artifact are found, when softare module exists ")
|
||||
public void testArtifactsExists() throws Exception {
|
||||
@Description("Ensures that artifacts are found, when software module exists.")
|
||||
public void artifactsExists() throws Exception {
|
||||
final Target target = TestDataUtil.createTarget(targetManagement);
|
||||
final DistributionSet distributionSet = TestDataUtil.generateDistributionSet("", softwareManagement,
|
||||
distributionSetManagement);
|
||||
@@ -91,24 +91,6 @@ public class DeploymentBaseTest extends AbstractIntegrationTestWithMongoDB {
|
||||
|
||||
}
|
||||
|
||||
@Test()
|
||||
@Description("Ensures that software modules are found, when assigned distribution set exists with modules and atrifacts")
|
||||
public void testAvailableSoftwareModulesWithArtifacts() throws Exception {
|
||||
final Target target = TestDataUtil.createTarget(targetManagement);
|
||||
final DistributionSet distributionSet = TestDataUtil.generateDistributionSet("", softwareManagement,
|
||||
distributionSetManagement);
|
||||
|
||||
deploymentManagement.assignDistributionSet(distributionSet.getId(), new String[] { target.getName() });
|
||||
final Long softwareModuleId = distributionSet.getModules().stream().findFirst().get().getId();
|
||||
TestDataUtil.generateArtifacts(artifactManagement, softwareModuleId);
|
||||
|
||||
final int modulesSize = distributionSet.getModules().size();
|
||||
|
||||
mvc.perform(get("/{tenant}/controller/v1/{targetExist}/softwaremodules/", tenantAware.getCurrentTenant(),
|
||||
target.getName())).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$", hasSize(modulesSize)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Forced deployment to a controller. Checks if the resource reponse payload for a given deployment is as expected.")
|
||||
public void deplomentForceAction() throws Exception {
|
||||
@@ -160,7 +142,6 @@ public class DeploymentBaseTest extends AbstractIntegrationTestWithMongoDB {
|
||||
assertThat(actionStatusRepository.findAll()).hasSize(2);
|
||||
|
||||
current = System.currentTimeMillis();
|
||||
Thread.sleep(1);
|
||||
|
||||
final DistributionSet findDistributionSetByAction = distributionSetManagement
|
||||
.findDistributionSetByAction(action);
|
||||
@@ -284,7 +265,6 @@ public class DeploymentBaseTest extends AbstractIntegrationTestWithMongoDB {
|
||||
assertThat(actionStatusRepository.findAll()).hasSize(2);
|
||||
|
||||
current = System.currentTimeMillis();
|
||||
Thread.sleep(1);
|
||||
|
||||
final DistributionSet findDistributionSetByAction = distributionSetManagement
|
||||
.findDistributionSetByAction(action);
|
||||
@@ -407,7 +387,6 @@ public class DeploymentBaseTest extends AbstractIntegrationTestWithMongoDB {
|
||||
assertThat(actionStatusRepository.findAll()).hasSize(2);
|
||||
|
||||
current = System.currentTimeMillis();
|
||||
Thread.sleep(1);
|
||||
|
||||
final DistributionSet findDistributionSetByAction = distributionSetManagement
|
||||
.findDistributionSetByAction(action);
|
||||
@@ -584,17 +563,11 @@ public class DeploymentBaseTest extends AbstractIntegrationTestWithMongoDB {
|
||||
|
||||
long current = System.currentTimeMillis();
|
||||
long lastModified = targetManagement.findTargetByControllerID("4712").getLastModifiedAt();
|
||||
Thread.sleep(1); // is required: otherwise processing the next line is
|
||||
// often too fast and
|
||||
// the following assert will fail
|
||||
mvc.perform(post("/{tenant}/controller/v1/4712/deploymentBase/" + action1.getId() + "/feedback",
|
||||
tenantAware.getCurrentTenant())
|
||||
.content(JsonBuilder.deploymentActionFeedback(action1.getId().toString(), "closed"))
|
||||
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
|
||||
Thread.sleep(1); // is required: otherwise processing the next line is
|
||||
// often too fast and
|
||||
// the following assert will fail
|
||||
myT = targetManagement.findTargetByControllerIDWithDetails("4712");
|
||||
assertThat(myT.getTargetInfo().getLastTargetQuery()).isLessThanOrEqualTo(System.currentTimeMillis());
|
||||
assertThat(myT.getTargetInfo().getLastTargetQuery()).isGreaterThanOrEqualTo(current);
|
||||
@@ -615,17 +588,11 @@ public class DeploymentBaseTest extends AbstractIntegrationTestWithMongoDB {
|
||||
// action2 done
|
||||
current = System.currentTimeMillis();
|
||||
lastModified = targetManagement.findTargetByControllerID("4712").getLastModifiedAt();
|
||||
Thread.sleep(1); // is required: otherwise processing the next line is
|
||||
// often too fast and
|
||||
// the following assert will fail
|
||||
mvc.perform(post("/{tenant}/controller/v1/4712/deploymentBase/" + action2.getId() + "/feedback",
|
||||
tenantAware.getCurrentTenant())
|
||||
.content(JsonBuilder.deploymentActionFeedback(action2.getId().toString(), "closed"))
|
||||
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
|
||||
Thread.sleep(1); // is required: otherwise processing the next line is
|
||||
// often too fast and
|
||||
// the following assert will fail
|
||||
myT = targetManagement.findTargetByControllerIDWithDetails("4712");
|
||||
assertThat(myT.getTargetInfo().getLastTargetQuery()).isLessThanOrEqualTo(System.currentTimeMillis());
|
||||
assertThat(myT.getTargetInfo().getLastTargetQuery()).isGreaterThanOrEqualTo(current);
|
||||
@@ -641,18 +608,11 @@ public class DeploymentBaseTest extends AbstractIntegrationTestWithMongoDB {
|
||||
// action3 done
|
||||
current = System.currentTimeMillis();
|
||||
lastModified = targetManagement.findTargetByControllerID("4712").getLastModifiedAt();
|
||||
Thread.sleep(1); // is required: otherwise processing the next line is
|
||||
// often too fast and
|
||||
// the following assert will fail
|
||||
mvc.perform(post("/{tenant}/controller/v1/4712/deploymentBase/" + action3.getId() + "/feedback",
|
||||
tenantAware.getCurrentTenant())
|
||||
.content(JsonBuilder.deploymentActionFeedback(action3.getId().toString(), "closed"))
|
||||
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
|
||||
Thread.sleep(1); // is required: otherwise processing the next line is
|
||||
// often too fast and
|
||||
// the following assert will fail
|
||||
|
||||
myT = targetManagement.findTargetByControllerID("4712");
|
||||
assertThat(myT.getTargetInfo().getLastTargetQuery()).isLessThanOrEqualTo(System.currentTimeMillis());
|
||||
assertThat(myT.getTargetInfo().getLastTargetQuery()).isGreaterThanOrEqualTo(current);
|
||||
@@ -684,17 +644,12 @@ public class DeploymentBaseTest extends AbstractIntegrationTestWithMongoDB {
|
||||
|
||||
long current = System.currentTimeMillis();
|
||||
long lastModified = targetManagement.findTargetByControllerID("4712").getLastModifiedAt();
|
||||
Thread.sleep(1); // is required: otherwise processing the next line is
|
||||
// often too fast and
|
||||
// the following assert will fail
|
||||
mvc.perform(post("/{tenant}/controller/v1/4712/deploymentBase/" + action.getId() + "/feedback",
|
||||
tenantAware.getCurrentTenant())
|
||||
.content(JsonBuilder.deploymentActionFeedback(action.getId().toString(), "closed", "failure"))
|
||||
.content(JsonBuilder.deploymentActionFeedback(action.getId().toString(), "closed", "failure",
|
||||
"error message"))
|
||||
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
|
||||
Thread.sleep(1); // is required: otherwise processing the next line is
|
||||
// often too fast and
|
||||
// the following assert will fail
|
||||
Target myT = targetManagement.findTargetByControllerID("4712");
|
||||
assertThat(myT.getTargetInfo().getLastTargetQuery()).isLessThanOrEqualTo(System.currentTimeMillis());
|
||||
assertThat(myT.getTargetInfo().getLastTargetQuery()).isGreaterThanOrEqualTo(current);
|
||||
@@ -720,17 +675,13 @@ public class DeploymentBaseTest extends AbstractIntegrationTestWithMongoDB {
|
||||
final Action action2 = deploymentManagement.findActiveActionsByTarget(myT).get(0);
|
||||
current = System.currentTimeMillis();
|
||||
lastModified = targetManagement.findTargetByControllerID("4712").getLastModifiedAt();
|
||||
Thread.sleep(1); // is required: otherwise processing the next line is
|
||||
// often too fast and
|
||||
// the following assert will fail
|
||||
|
||||
mvc.perform(post("/{tenant}/controller/v1/4712/deploymentBase/" + action2.getId() + "/feedback",
|
||||
tenantAware.getCurrentTenant())
|
||||
.content(JsonBuilder.deploymentActionFeedback(action2.getId().toString(), "closed", "success"))
|
||||
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
|
||||
Thread.sleep(1); // is required: otherwise processing the next line is
|
||||
// often too fast and
|
||||
// the following assert will fail
|
||||
|
||||
myT = targetManagement.findTargetByControllerID("4712");
|
||||
assertThat(myT.getTargetInfo().getLastTargetQuery()).isLessThanOrEqualTo(System.currentTimeMillis());
|
||||
assertThat(myT.getTargetInfo().getLastTargetQuery()).isGreaterThanOrEqualTo(current);
|
||||
|
||||
57
hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/controller/RootControllerTest.java
Executable file → Normal file
57
hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/controller/RootControllerTest.java
Executable file → Normal file
@@ -10,7 +10,6 @@ package org.eclipse.hawkbit.controller;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
@@ -22,9 +21,8 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import org.eclipse.hawkbit.AbstractIntegrationTest;
|
||||
import org.eclipse.hawkbit.AbstractIntegrationTestWithMongoDB;
|
||||
import org.eclipse.hawkbit.MockMvcResultPrinter;
|
||||
import org.eclipse.hawkbit.TestDataUtil;
|
||||
import org.eclipse.hawkbit.WithSpringAuthorityRule;
|
||||
@@ -51,40 +49,7 @@ import ru.yandex.qatools.allure.annotations.Stories;
|
||||
@Stories("Root Poll Resource")
|
||||
// TODO: fully document tests -> @Description for long text and reasonable
|
||||
// method name as short text
|
||||
public class RootControllerTest extends AbstractIntegrationTest {
|
||||
|
||||
@Test()
|
||||
@Description("Ensures that software modules are not found, when target does not exists ")
|
||||
public void testSoftwareModulesIfTargetNotExists() throws Exception {
|
||||
final String targetNotExist = "targetNotExist";
|
||||
mvc.perform(get("/{tenant}/controller/v1/{targetNotExist}/softwaremodules/", tenantAware.getCurrentTenant(),
|
||||
targetNotExist)).andDo(MockMvcResultPrinter.print()).andExpect(status().isNotFound());
|
||||
|
||||
}
|
||||
|
||||
@Test()
|
||||
@Description("Ensures that software modules are not found, when assigned distribution set exists with no modules")
|
||||
public void testSoftwareModulesEmptyIfDistributionSetNotExists() throws Exception {
|
||||
mvc.perform(get("/{tenant}/controller/v1/{targetExist}/softwaremodules/", tenantAware.getCurrentTenant(),
|
||||
TestDataUtil.createTarget(targetManagement).getName())).andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isOk()).andExpect(jsonPath("$", hasSize(0)));
|
||||
}
|
||||
|
||||
@Test()
|
||||
@Description("Ensures that software modules are found, when assigned distribution set exists with modules")
|
||||
public void testAvailableSoftwareModulesWithNoArtifacts() throws Exception {
|
||||
final Target target = TestDataUtil.createTarget(targetManagement);
|
||||
final DistributionSet distributionSet = TestDataUtil.generateDistributionSet("", softwareManagement,
|
||||
distributionSetManagement);
|
||||
|
||||
deploymentManagement.assignDistributionSet(distributionSet.getId(), new String[] { target.getName() });
|
||||
|
||||
final int modulesSize = distributionSet.getModules().size();
|
||||
|
||||
mvc.perform(get("/{tenant}/controller/v1/{targetExist}/softwaremodules/", tenantAware.getCurrentTenant(),
|
||||
target.getName())).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$", hasSize(modulesSize)));
|
||||
}
|
||||
public class RootControllerTest extends AbstractIntegrationTestWithMongoDB {
|
||||
|
||||
@Test()
|
||||
@Description("Ensures that targets cannot be created e.g. in plug'n play scenarios when tenant does not exists but can be created if the tenant exists.")
|
||||
@@ -105,7 +70,6 @@ public class RootControllerTest extends AbstractIntegrationTest {
|
||||
|
||||
mvc.perform(get("/{}/controller/v1/aControllerId", tenantAware.getCurrentTenant()))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isBadRequest());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -123,15 +87,11 @@ public class RootControllerTest extends AbstractIntegrationTest {
|
||||
// make a poll, audit information should not be changed, run as
|
||||
// controller principal!
|
||||
securityRule.runAs(
|
||||
WithSpringAuthorityRule.withUser("controller", SpringEvalExpressions.CONTROLLER_ROLE_ANONYMOUS),
|
||||
new Callable<Void>() {
|
||||
@Override
|
||||
public Void call() throws Exception {
|
||||
mvc.perform(get("/{tenant}/controller/v1/" + knownTargetControllerId,
|
||||
tenantAware.getCurrentTenant())).andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isOk());
|
||||
return null;
|
||||
}
|
||||
WithSpringAuthorityRule.withUser("controller", SpringEvalExpressions.CONTROLLER_ROLE_ANONYMOUS), () -> {
|
||||
mvc.perform(
|
||||
get("/{tenant}/controller/v1/" + knownTargetControllerId, tenantAware.getCurrentTenant()))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
|
||||
return null;
|
||||
});
|
||||
|
||||
// verify that audit information has not changed
|
||||
@@ -249,9 +209,6 @@ public class RootControllerTest extends AbstractIntegrationTest {
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
.andExpect(content().contentType(MediaTypes.HAL_JSON))
|
||||
.andExpect(jsonPath("$config.polling.sleep", equalTo("00:01:00")));
|
||||
Thread.sleep(1); // is required: otherwise processing the next line is
|
||||
// often too fast and
|
||||
// the following assert will fail
|
||||
assertThat(targetManagement.findTargetByControllerID("4711").getTargetInfo().getLastTargetQuery())
|
||||
.isLessThanOrEqualTo(System.currentTimeMillis());
|
||||
assertThat(targetManagement.findTargetByControllerID("4711").getTargetInfo().getLastTargetQuery())
|
||||
|
||||
388
hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/DistributionSetResourceTest.java
Executable file → Normal file
388
hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/DistributionSetResourceTest.java
Executable file → Normal file
@@ -30,6 +30,11 @@ import org.eclipse.hawkbit.AbstractIntegrationTest;
|
||||
import org.eclipse.hawkbit.MockMvcResultPrinter;
|
||||
import org.eclipse.hawkbit.TestDataUtil;
|
||||
import org.eclipse.hawkbit.WithUser;
|
||||
import org.eclipse.hawkbit.repository.ActionRepository;
|
||||
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.exception.EntityNotFoundException;
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.Action.Status;
|
||||
@@ -48,12 +53,12 @@ import org.springframework.context.annotation.Description;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.MvcResult;
|
||||
|
||||
import ru.yandex.qatools.allure.annotations.Features;
|
||||
import ru.yandex.qatools.allure.annotations.Stories;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.jayway.jsonpath.JsonPath;
|
||||
|
||||
import ru.yandex.qatools.allure.annotations.Features;
|
||||
import ru.yandex.qatools.allure.annotations.Stories;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
@@ -78,7 +83,7 @@ public class DistributionSetResourceTest extends AbstractIntegrationTest {
|
||||
|
||||
@Test
|
||||
@Description("This test verifies the deletion of a assigned Software Module of a Distribution Set can not be achieved when that Distribution Set has been assigned or installed to a target.")
|
||||
public void testDeleteFailureWhenDistributionSetInUse() throws Exception {
|
||||
public void deleteFailureWhenDistributionSetInUse() throws Exception {
|
||||
|
||||
// create DisSet
|
||||
final DistributionSet disSet = TestDataUtil.generateDistributionSetWithNoSoftwareModules("Eris", "560a",
|
||||
@@ -92,10 +97,9 @@ public class DistributionSetResourceTest extends AbstractIntegrationTest {
|
||||
smList.put(new JSONObject().put("id", Long.valueOf(smID)));
|
||||
}
|
||||
// post assignment
|
||||
mvc.perform(
|
||||
post(RestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + disSet.getId() + "/assignedSM")
|
||||
.contentType(MediaType.APPLICATION_JSON).content(smList.toString()))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
|
||||
mvc.perform(post(RestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + disSet.getId() + "/assignedSM")
|
||||
.contentType(MediaType.APPLICATION_JSON).content(smList.toString())).andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isOk());
|
||||
|
||||
// create targets and assign DisSet to target
|
||||
final String[] knownTargetIds = new String[] { "1", "2" };
|
||||
@@ -105,32 +109,29 @@ public class DistributionSetResourceTest extends AbstractIntegrationTest {
|
||||
list.put(new JSONObject().put("id", Long.valueOf(targetId)));
|
||||
}
|
||||
deploymentManagement.assignDistributionSet(disSet.getId(), knownTargetIds[0]);
|
||||
mvc.perform(
|
||||
post(RestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + disSet.getId() + "/assignedTargets")
|
||||
.contentType(MediaType.APPLICATION_JSON).content(list.toString()))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.assigned", equalTo(knownTargetIds.length - 1)))
|
||||
mvc.perform(post(RestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + disSet.getId() + "/assignedTargets")
|
||||
.contentType(MediaType.APPLICATION_JSON).content(list.toString())).andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isOk()).andExpect(jsonPath("$.assigned", equalTo(knownTargetIds.length - 1)))
|
||||
.andExpect(jsonPath("$.alreadyAssigned", equalTo(1)))
|
||||
.andExpect(jsonPath("$.total", equalTo(knownTargetIds.length)));
|
||||
|
||||
// try to delete the Software Module from DisSet that has been assigned
|
||||
// try to delete the Software Module from DistSet that has been assigned
|
||||
// to the target.
|
||||
mvc.perform(
|
||||
delete(
|
||||
RestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + disSet.getId() + "/assignedSM/"
|
||||
+ smIDs.get(0)).contentType(MediaType.APPLICATION_JSON))
|
||||
mvc.perform(delete(
|
||||
RestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + disSet.getId() + "/assignedSM/" + smIDs.get(0))
|
||||
.contentType(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isLocked())
|
||||
.andExpect(jsonPath("$.errorCode", equalTo("hawkbit.server.error.entitiylocked")));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("This test verifies that the assignment of a Software Module to a Distribution Set can not be achieved when that Distribution Set has been assigned or installed to a target.")
|
||||
public void testAssignmentFailureWhenAssigningToUsedDistributionSet() throws Exception {
|
||||
public void assignmentFailureWhenAssigningToUsedDistributionSet() throws Exception {
|
||||
|
||||
// create DisSet
|
||||
final DistributionSet disSet = TestDataUtil.generateDistributionSetWithNoSoftwareModules("Mars", "686,980",
|
||||
distributionSetManagement);
|
||||
final List<Long> smIDs = new ArrayList<Long>();
|
||||
final List<Long> smIDs = new ArrayList<>();
|
||||
SoftwareModule sm = new SoftwareModule(osType, "Phobos", "0,3189", null, null);
|
||||
sm = softwareManagement.createSoftwareModule(sm);
|
||||
smIDs.add(sm.getId());
|
||||
@@ -139,10 +140,9 @@ public class DistributionSetResourceTest extends AbstractIntegrationTest {
|
||||
smList.put(new JSONObject().put("id", Long.valueOf(smID)));
|
||||
}
|
||||
// post assignment
|
||||
mvc.perform(
|
||||
post(RestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + disSet.getId() + "/assignedSM")
|
||||
.contentType(MediaType.APPLICATION_JSON).content(smList.toString()))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
|
||||
mvc.perform(post(RestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + disSet.getId() + "/assignedSM")
|
||||
.contentType(MediaType.APPLICATION_JSON).content(smList.toString())).andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isOk());
|
||||
|
||||
// create Targets
|
||||
final String[] knownTargetIds = new String[] { "1", "2" };
|
||||
@@ -153,11 +153,9 @@ public class DistributionSetResourceTest extends AbstractIntegrationTest {
|
||||
}
|
||||
// assign DisSet to target and test assignment
|
||||
deploymentManagement.assignDistributionSet(disSet.getId(), knownTargetIds[0]);
|
||||
mvc.perform(
|
||||
post(RestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + disSet.getId() + "/assignedTargets")
|
||||
.contentType(MediaType.APPLICATION_JSON).content(list.toString()))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.assigned", equalTo(knownTargetIds.length - 1)))
|
||||
mvc.perform(post(RestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + disSet.getId() + "/assignedTargets")
|
||||
.contentType(MediaType.APPLICATION_JSON).content(list.toString())).andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isOk()).andExpect(jsonPath("$.assigned", equalTo(knownTargetIds.length - 1)))
|
||||
.andExpect(jsonPath("$.alreadyAssigned", equalTo(1)))
|
||||
.andExpect(jsonPath("$.total", equalTo(knownTargetIds.length)));
|
||||
|
||||
@@ -171,9 +169,8 @@ public class DistributionSetResourceTest extends AbstractIntegrationTest {
|
||||
smList2.put(new JSONObject().put("id", Long.valueOf(smID)));
|
||||
}
|
||||
|
||||
mvc.perform(
|
||||
post(RestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + disSet.getId() + "/assignedSM")
|
||||
.contentType(MediaType.APPLICATION_JSON).content(smList2.toString()))
|
||||
mvc.perform(post(RestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + disSet.getId() + "/assignedSM")
|
||||
.contentType(MediaType.APPLICATION_JSON).content(smList2.toString()))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isLocked())
|
||||
.andExpect(jsonPath("$.errorCode", equalTo("hawkbit.server.error.entitiylocked")));
|
||||
}
|
||||
@@ -205,10 +202,9 @@ public class DistributionSetResourceTest extends AbstractIntegrationTest {
|
||||
list.put(new JSONObject().put("id", Long.valueOf(smID)));
|
||||
}
|
||||
// post assignment
|
||||
mvc.perform(
|
||||
post(RestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + disSet.getId() + "/assignedSM")
|
||||
.contentType(MediaType.APPLICATION_JSON).content(list.toString()))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
|
||||
mvc.perform(post(RestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + disSet.getId() + "/assignedSM")
|
||||
.contentType(MediaType.APPLICATION_JSON).content(list.toString())).andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isOk());
|
||||
// Test if size is 3
|
||||
mvc.perform(get(RestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + disSet.getId() + "/assignedSM"))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
@@ -216,7 +212,7 @@ public class DistributionSetResourceTest extends AbstractIntegrationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("This test verifies the rejection of Software Modules of a Distribution Set through the RESTful API.")
|
||||
@Description("This test verifies the removal of Software Modules of a Distribution Set through the RESTful API.")
|
||||
public void unassignSoftwaremoduleFromDistributionSet() throws Exception {
|
||||
|
||||
// Create DistributionSet with three software modules
|
||||
@@ -226,11 +222,11 @@ public class DistributionSetResourceTest extends AbstractIntegrationTest {
|
||||
mvc.perform(get(RestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + set.getId() + "/assignedSM"))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.size", equalTo(amountOfSM)));
|
||||
// test the rejection of all assigned software modules one by one
|
||||
// test the removal of all software modules one by one
|
||||
for (final Iterator<SoftwareModule> iter = set.getModules().iterator(); iter.hasNext();) {
|
||||
final Long smId = iter.next().getId();
|
||||
mvc.perform(
|
||||
delete(RestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + set.getId() + "/assignedSM/" + smId))
|
||||
mvc.perform(delete(
|
||||
RestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + set.getId() + "/assignedSM/" + smId))
|
||||
.andExpect(status().isOk());
|
||||
mvc.perform(get(RestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + set.getId() + "/assignedSM"))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
@@ -255,8 +251,8 @@ public class DistributionSetResourceTest extends AbstractIntegrationTest {
|
||||
|
||||
mvc.perform(
|
||||
post(RestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + createdDs.getId() + "/assignedTargets")
|
||||
.contentType(MediaType.APPLICATION_JSON).content(list.toString())).andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.assigned", equalTo(knownTargetIds.length - 1)))
|
||||
.contentType(MediaType.APPLICATION_JSON).content(list.toString()))
|
||||
.andExpect(status().isOk()).andExpect(jsonPath("$.assigned", equalTo(knownTargetIds.length - 1)))
|
||||
.andExpect(jsonPath("$.alreadyAssigned", equalTo(1)))
|
||||
.andExpect(jsonPath("$.total", equalTo(knownTargetIds.length)));
|
||||
}
|
||||
@@ -299,7 +295,8 @@ public class DistributionSetResourceTest extends AbstractIntegrationTest {
|
||||
// assign knownTargetId to distribution set
|
||||
deploymentManagement.assignDistributionSet(createdDs.getId(), knownTargetId);
|
||||
// make it in install state
|
||||
sendUpdateActionStatusToTargets(createdDs, Lists.newArrayList(createTarget), Status.FINISHED, "some message");
|
||||
sendUpdateActionStatusToTargets(controllerManagament, targetManagement, actionRepository, createdDs,
|
||||
Lists.newArrayList(createTarget), Status.FINISHED, "some message");
|
||||
|
||||
mvc.perform(
|
||||
get(RestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + createdDs.getId() + "/installedTargets"))
|
||||
@@ -308,7 +305,7 @@ public class DistributionSetResourceTest extends AbstractIntegrationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDistributionSetsWithoutAddtionalRequestParameters() throws Exception {
|
||||
public void getDistributionSetsWithoutAddtionalRequestParameters() throws Exception {
|
||||
final int modules = 5;
|
||||
createDistributionSetsAlphabetical(modules);
|
||||
mvc.perform(get(RestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING)).andDo(MockMvcResultPrinter.print())
|
||||
@@ -319,13 +316,12 @@ public class DistributionSetResourceTest extends AbstractIntegrationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDistributionSetsWithPagingLimitRequestParameter() throws Exception {
|
||||
public void getDistributionSetsWithPagingLimitRequestParameter() throws Exception {
|
||||
final int modules = 5;
|
||||
final int limitSize = 1;
|
||||
createDistributionSetsAlphabetical(modules);
|
||||
mvc.perform(
|
||||
get(RestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING).param(
|
||||
RestConstants.REQUEST_PARAMETER_PAGING_LIMIT, String.valueOf(limitSize)))
|
||||
mvc.perform(get(RestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING)
|
||||
.param(RestConstants.REQUEST_PARAMETER_PAGING_LIMIT, String.valueOf(limitSize)))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
.andExpect(jsonPath(TargetResourceTest.JSON_PATH_PAGED_LIST_TOTAL, equalTo(modules)))
|
||||
.andExpect(jsonPath(TargetResourceTest.JSON_PATH_PAGED_LIST_SIZE, equalTo(limitSize)))
|
||||
@@ -333,15 +329,14 @@ public class DistributionSetResourceTest extends AbstractIntegrationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDistributionSetsWithPagingLimitAndOffsetRequestParameter() throws Exception {
|
||||
public void getDistributionSetsWithPagingLimitAndOffsetRequestParameter() throws Exception {
|
||||
final int modules = 5;
|
||||
final int offsetParam = 2;
|
||||
final int expectedSize = modules - offsetParam;
|
||||
createDistributionSetsAlphabetical(modules);
|
||||
mvc.perform(
|
||||
get(RestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING).param(
|
||||
RestConstants.REQUEST_PARAMETER_PAGING_OFFSET, String.valueOf(offsetParam)).param(
|
||||
RestConstants.REQUEST_PARAMETER_PAGING_LIMIT, String.valueOf(modules)))
|
||||
mvc.perform(get(RestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING)
|
||||
.param(RestConstants.REQUEST_PARAMETER_PAGING_OFFSET, String.valueOf(offsetParam))
|
||||
.param(RestConstants.REQUEST_PARAMETER_PAGING_LIMIT, String.valueOf(modules)))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
.andExpect(jsonPath(TargetResourceTest.JSON_PATH_PAGED_LIST_TOTAL, equalTo(modules)))
|
||||
.andExpect(jsonPath(TargetResourceTest.JSON_PATH_PAGED_LIST_SIZE, equalTo(expectedSize)))
|
||||
@@ -350,12 +345,12 @@ public class DistributionSetResourceTest extends AbstractIntegrationTest {
|
||||
|
||||
@Test
|
||||
@WithUser(principal = "uploadTester", allSpPermissions = true)
|
||||
public void testGetDistributionSets() throws Exception {
|
||||
public void getDistributionSets() throws Exception {
|
||||
// prepare test data
|
||||
assertThat(distributionSetManagement.findDistributionSetsAll(pageReq, false, true)).hasSize(0);
|
||||
|
||||
DistributionSet set = TestDataUtil
|
||||
.generateDistributionSet("one", softwareManagement, distributionSetManagement);
|
||||
DistributionSet set = TestDataUtil.generateDistributionSet("one", softwareManagement,
|
||||
distributionSetManagement);
|
||||
set.setRequiredMigrationStep(set.isRequiredMigrationStep());
|
||||
set = distributionSetManagement.updateDistributionSet(set);
|
||||
|
||||
@@ -369,12 +364,10 @@ public class DistributionSetResourceTest extends AbstractIntegrationTest {
|
||||
|
||||
// perform request
|
||||
mvc.perform(get("/rest/v1/distributionsets").accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isOk())
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
|
||||
.andExpect(
|
||||
jsonPath("$content.[0]._links.self.href", equalTo("http://localhost/rest/v1/distributionsets/"
|
||||
+ set.getId())))
|
||||
.andExpect(jsonPath("$content.[0]._links.self.href",
|
||||
equalTo("http://localhost/rest/v1/distributionsets/" + set.getId())))
|
||||
.andExpect(jsonPath("$content.[0].id", equalTo(set.getId().intValue())))
|
||||
.andExpect(jsonPath("$content.[0].name", equalTo(set.getName())))
|
||||
.andExpect(jsonPath("$content.[0].requiredMigrationStep", equalTo(set.isRequiredMigrationStep())))
|
||||
@@ -386,41 +379,25 @@ public class DistributionSetResourceTest extends AbstractIntegrationTest {
|
||||
.andExpect(jsonPath("$content.[0].lastModifiedBy", equalTo(set.getLastModifiedBy())))
|
||||
.andExpect(jsonPath("$content.[0].lastModifiedAt", equalTo(set.getLastModifiedAt())))
|
||||
.andExpect(jsonPath("$content.[0].version", equalTo(set.getVersion())))
|
||||
.andExpect(
|
||||
jsonPath("$content.[0].modules.[?(@.type==" + runtimeType.getKey() + ")][0].id", equalTo(set
|
||||
.findFirstModuleByType(runtimeType).getId().intValue())))
|
||||
.andExpect(
|
||||
jsonPath("$content.[0].modules.[?(@.type==" + appType.getKey() + ")][0].id", equalTo(set
|
||||
.findFirstModuleByType(appType).getId().intValue())))
|
||||
.andExpect(
|
||||
jsonPath("$content.[0].modules.[?(@.type==" + osType.getKey() + ")][0].id", equalTo(set
|
||||
.findFirstModuleByType(osType).getId().intValue())));
|
||||
.andExpect(jsonPath("$content.[0].modules.[?(@.type==" + runtimeType.getKey() + ")][0].id",
|
||||
equalTo(set.findFirstModuleByType(runtimeType).getId().intValue())))
|
||||
.andExpect(jsonPath("$content.[0].modules.[?(@.type==" + appType.getKey() + ")][0].id",
|
||||
equalTo(set.findFirstModuleByType(appType).getId().intValue())))
|
||||
.andExpect(jsonPath("$content.[0].modules.[?(@.type==" + osType.getKey() + ")][0].id",
|
||||
equalTo(set.findFirstModuleByType(osType).getId().intValue())));
|
||||
}
|
||||
|
||||
@Test
|
||||
@WithUser(principal = "uploadTester", allSpPermissions = true)
|
||||
public void testGetDistributionSet() throws Exception {
|
||||
// prepare test data
|
||||
assertThat(distributionSetManagement.findDistributionSetsAll(pageReq, false, true)).hasSize(0);
|
||||
|
||||
DistributionSet set = TestDataUtil
|
||||
.generateDistributionSet("one", softwareManagement, distributionSetManagement);
|
||||
set.setVersion("anotherVersion");
|
||||
set = distributionSetManagement.updateDistributionSet(set);
|
||||
|
||||
// load also lazy stuff
|
||||
set = distributionSetManagement.findDistributionSetByIdWithDetails(set.getId());
|
||||
|
||||
assertThat(distributionSetManagement.findDistributionSetsAll(pageReq, false, true)).hasSize(1);
|
||||
public void getDistributionSet() throws Exception {
|
||||
final DistributionSet set = createTestDistributionSet(softwareManagement, distributionSetManagement);
|
||||
|
||||
// perform request
|
||||
mvc.perform(get("/rest/v1/distributionsets/{dsId}", set.getId()).accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isOk())
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
|
||||
.andExpect(
|
||||
jsonPath("$_links.self.href",
|
||||
equalTo("http://localhost/rest/v1/distributionsets/" + set.getId())))
|
||||
.andExpect(jsonPath("$_links.self.href",
|
||||
equalTo("http://localhost/rest/v1/distributionsets/" + set.getId())))
|
||||
.andExpect(jsonPath("$id", equalTo(set.getId().intValue())))
|
||||
.andExpect(jsonPath("$name", equalTo(set.getName())))
|
||||
.andExpect(jsonPath("$type", equalTo(set.getType().getKey())))
|
||||
@@ -432,29 +409,26 @@ public class DistributionSetResourceTest extends AbstractIntegrationTest {
|
||||
.andExpect(jsonPath("$lastModifiedBy", equalTo(set.getLastModifiedBy())))
|
||||
.andExpect(jsonPath("$lastModifiedAt", equalTo(set.getLastModifiedAt())))
|
||||
.andExpect(jsonPath("$version", equalTo(set.getVersion())))
|
||||
.andExpect(
|
||||
jsonPath("$modules.[?(@.type==" + runtimeType.getKey() + ")][0].id", equalTo(set
|
||||
.findFirstModuleByType(runtimeType).getId().intValue())))
|
||||
.andExpect(
|
||||
jsonPath("$modules.[?(@.type==" + appType.getKey() + ")][0].id", equalTo(set
|
||||
.findFirstModuleByType(appType).getId().intValue())))
|
||||
.andExpect(
|
||||
jsonPath("$modules.[?(@.type==" + osType.getKey() + ")][0].id", equalTo(set
|
||||
.findFirstModuleByType(osType).getId().intValue())));
|
||||
.andExpect(jsonPath("$modules.[?(@.type==" + runtimeType.getKey() + ")][0].id",
|
||||
equalTo(set.findFirstModuleByType(runtimeType).getId().intValue())))
|
||||
.andExpect(jsonPath("$modules.[?(@.type==" + appType.getKey() + ")][0].id",
|
||||
equalTo(set.findFirstModuleByType(appType).getId().intValue())))
|
||||
.andExpect(jsonPath("$modules.[?(@.type==" + osType.getKey() + ")][0].id",
|
||||
equalTo(set.findFirstModuleByType(osType).getId().intValue())));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@WithUser(principal = "uploadTester", allSpPermissions = true)
|
||||
public void testCreateDistributionSets() throws JSONException, Exception {
|
||||
public void createDistributionSets() throws JSONException, Exception {
|
||||
assertThat(distributionSetManagement.findDistributionSetsAll(pageReq, false, true)).hasSize(0);
|
||||
|
||||
final SoftwareModule ah = softwareManagement.createSoftwareModule(new SoftwareModule(appType, "agent-hub",
|
||||
"1.0.1", null, ""));
|
||||
final SoftwareModule jvm = softwareManagement.createSoftwareModule(new SoftwareModule(runtimeType,
|
||||
"oracle-jre", "1.7.2", null, ""));
|
||||
final SoftwareModule os = softwareManagement.createSoftwareModule(new SoftwareModule(osType, "poky", "3.0.2",
|
||||
null, ""));
|
||||
final SoftwareModule ah = softwareManagement
|
||||
.createSoftwareModule(new SoftwareModule(appType, "agent-hub", "1.0.1", null, ""));
|
||||
final SoftwareModule jvm = softwareManagement
|
||||
.createSoftwareModule(new SoftwareModule(runtimeType, "oracle-jre", "1.7.2", null, ""));
|
||||
final SoftwareModule os = softwareManagement
|
||||
.createSoftwareModule(new SoftwareModule(osType, "poky", "3.0.2", null, ""));
|
||||
|
||||
DistributionSet one = TestDataUtil.buildDistributionSet("one", "one", standardDsType, os, jvm, ah);
|
||||
DistributionSet two = TestDataUtil.buildDistributionSet("two", "two", standardDsType, os, jvm, ah);
|
||||
@@ -469,11 +443,9 @@ public class DistributionSetResourceTest extends AbstractIntegrationTest {
|
||||
final long current = System.currentTimeMillis();
|
||||
|
||||
final MvcResult mvcResult = mvc
|
||||
.perform(
|
||||
post("/rest/v1/distributionsets/").content(JsonBuilder.distributionSets(sets))
|
||||
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isCreated())
|
||||
.perform(post("/rest/v1/distributionsets/").content(JsonBuilder.distributionSets(sets))
|
||||
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isCreated())
|
||||
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("[0]name", equalTo(one.getName())))
|
||||
.andExpect(jsonPath("[0]description", equalTo(one.getDescription())))
|
||||
@@ -482,30 +454,24 @@ public class DistributionSetResourceTest extends AbstractIntegrationTest {
|
||||
.andExpect(jsonPath("[0]version", equalTo(one.getVersion())))
|
||||
.andExpect(jsonPath("[0]complete", equalTo(Boolean.TRUE)))
|
||||
.andExpect(jsonPath("[0]requiredMigrationStep", equalTo(one.isRequiredMigrationStep())))
|
||||
.andExpect(
|
||||
jsonPath("[0].modules.[?(@.type==" + runtimeType.getKey() + ")][0].id", equalTo(one
|
||||
.findFirstModuleByType(runtimeType).getId().intValue())))
|
||||
.andExpect(
|
||||
jsonPath("[0].modules.[?(@.type==" + appType.getKey() + ")][0].id", equalTo(one
|
||||
.findFirstModuleByType(appType).getId().intValue())))
|
||||
.andExpect(
|
||||
jsonPath("[0].modules.[?(@.type==" + osType.getKey() + ")][0].id", equalTo(one
|
||||
.findFirstModuleByType(osType).getId().intValue())))
|
||||
.andExpect(jsonPath("[0].modules.[?(@.type==" + runtimeType.getKey() + ")][0].id",
|
||||
equalTo(one.findFirstModuleByType(runtimeType).getId().intValue())))
|
||||
.andExpect(jsonPath("[0].modules.[?(@.type==" + appType.getKey() + ")][0].id",
|
||||
equalTo(one.findFirstModuleByType(appType).getId().intValue())))
|
||||
.andExpect(jsonPath("[0].modules.[?(@.type==" + osType.getKey() + ")][0].id",
|
||||
equalTo(one.findFirstModuleByType(osType).getId().intValue())))
|
||||
.andExpect(jsonPath("[1]name", equalTo(two.getName())))
|
||||
.andExpect(jsonPath("[1]description", equalTo(two.getDescription())))
|
||||
.andExpect(jsonPath("[1]complete", equalTo(Boolean.TRUE)))
|
||||
.andExpect(jsonPath("[1]type", equalTo(standardDsType.getKey())))
|
||||
.andExpect(jsonPath("[1]createdBy", equalTo("uploadTester")))
|
||||
.andExpect(jsonPath("[1]version", equalTo(two.getVersion())))
|
||||
.andExpect(
|
||||
jsonPath("[1].modules.[?(@.type==" + runtimeType.getKey() + ")][0].id", equalTo(two
|
||||
.findFirstModuleByType(runtimeType).getId().intValue())))
|
||||
.andExpect(
|
||||
jsonPath("[1].modules.[?(@.type==" + appType.getKey() + ")][0].id", equalTo(two
|
||||
.findFirstModuleByType(appType).getId().intValue())))
|
||||
.andExpect(
|
||||
jsonPath("[1].modules.[?(@.type==" + osType.getKey() + ")][0].id", equalTo(two
|
||||
.findFirstModuleByType(osType).getId().intValue())))
|
||||
.andExpect(jsonPath("[1].modules.[?(@.type==" + runtimeType.getKey() + ")][0].id",
|
||||
equalTo(two.findFirstModuleByType(runtimeType).getId().intValue())))
|
||||
.andExpect(jsonPath("[1].modules.[?(@.type==" + appType.getKey() + ")][0].id",
|
||||
equalTo(two.findFirstModuleByType(appType).getId().intValue())))
|
||||
.andExpect(jsonPath("[1].modules.[?(@.type==" + osType.getKey() + ")][0].id",
|
||||
equalTo(two.findFirstModuleByType(osType).getId().intValue())))
|
||||
.andExpect(jsonPath("[1]requiredMigrationStep", equalTo(two.isRequiredMigrationStep())))
|
||||
.andExpect(jsonPath("[2]name", equalTo(three.getName())))
|
||||
.andExpect(jsonPath("[2]description", equalTo(three.getDescription())))
|
||||
@@ -513,51 +479,48 @@ public class DistributionSetResourceTest extends AbstractIntegrationTest {
|
||||
.andExpect(jsonPath("[2]type", equalTo(standardDsType.getKey())))
|
||||
.andExpect(jsonPath("[2]createdBy", equalTo("uploadTester")))
|
||||
.andExpect(jsonPath("[2]version", equalTo(three.getVersion())))
|
||||
.andExpect(
|
||||
jsonPath("[2].modules.[?(@.type==" + runtimeType.getKey() + ")][0].id", equalTo(three
|
||||
.findFirstModuleByType(runtimeType).getId().intValue())))
|
||||
.andExpect(
|
||||
jsonPath("[2].modules.[?(@.type==" + appType.getKey() + ")][0].id", equalTo(three
|
||||
.findFirstModuleByType(appType).getId().intValue())))
|
||||
.andExpect(
|
||||
jsonPath("[2].modules.[?(@.type==" + osType.getKey() + ")][0].id", equalTo(three
|
||||
.findFirstModuleByType(osType).getId().intValue())))
|
||||
.andExpect(jsonPath("[2].modules.[?(@.type==" + runtimeType.getKey() + ")][0].id",
|
||||
equalTo(three.findFirstModuleByType(runtimeType).getId().intValue())))
|
||||
.andExpect(jsonPath("[2].modules.[?(@.type==" + appType.getKey() + ")][0].id",
|
||||
equalTo(three.findFirstModuleByType(appType).getId().intValue())))
|
||||
.andExpect(jsonPath("[2].modules.[?(@.type==" + osType.getKey() + ")][0].id",
|
||||
equalTo(three.findFirstModuleByType(osType).getId().intValue())))
|
||||
.andExpect(jsonPath("[2]requiredMigrationStep", equalTo(three.isRequiredMigrationStep()))).andReturn();
|
||||
|
||||
one = distributionSetManagement.findDistributionSetByIdWithDetails(distributionSetManagement
|
||||
.findDistributionSetByNameAndVersion("one", "one").getId());
|
||||
two = distributionSetManagement.findDistributionSetByIdWithDetails(distributionSetManagement
|
||||
.findDistributionSetByNameAndVersion("two", "two").getId());
|
||||
three = distributionSetManagement.findDistributionSetByIdWithDetails(distributionSetManagement
|
||||
.findDistributionSetByNameAndVersion("three", "three").getId());
|
||||
one = distributionSetManagement.findDistributionSetByIdWithDetails(
|
||||
distributionSetManagement.findDistributionSetByNameAndVersion("one", "one").getId());
|
||||
two = distributionSetManagement.findDistributionSetByIdWithDetails(
|
||||
distributionSetManagement.findDistributionSetByNameAndVersion("two", "two").getId());
|
||||
three = distributionSetManagement.findDistributionSetByIdWithDetails(
|
||||
distributionSetManagement.findDistributionSetByNameAndVersion("three", "three").getId());
|
||||
|
||||
assertThat(
|
||||
JsonPath.compile("[0]_links.self.href").read(mvcResult.getResponse().getContentAsString()).toString())
|
||||
.isEqualTo("http://localhost/rest/v1/distributionsets/" + one.getId());
|
||||
.isEqualTo("http://localhost/rest/v1/distributionsets/" + one.getId());
|
||||
assertThat(
|
||||
JsonPath.compile("[0]_links.type.href").read(mvcResult.getResponse().getContentAsString()).toString())
|
||||
.isEqualTo("http://localhost/rest/v1/distributionsettypes/" + one.getType().getId());
|
||||
.isEqualTo("http://localhost/rest/v1/distributionsettypes/" + one.getType().getId());
|
||||
|
||||
assertThat(JsonPath.compile("[0]id").read(mvcResult.getResponse().getContentAsString()).toString()).isEqualTo(
|
||||
String.valueOf(one.getId()));
|
||||
assertThat(JsonPath.compile("[0]id").read(mvcResult.getResponse().getContentAsString()).toString())
|
||||
.isEqualTo(String.valueOf(one.getId()));
|
||||
assertThat(
|
||||
JsonPath.compile("[1]_links.self.href").read(mvcResult.getResponse().getContentAsString()).toString())
|
||||
.isEqualTo("http://localhost/rest/v1/distributionsets/" + two.getId());
|
||||
.isEqualTo("http://localhost/rest/v1/distributionsets/" + two.getId());
|
||||
assertThat(
|
||||
JsonPath.compile("[1]_links.type.href").read(mvcResult.getResponse().getContentAsString()).toString())
|
||||
.isEqualTo("http://localhost/rest/v1/distributionsettypes/" + two.getType().getId());
|
||||
.isEqualTo("http://localhost/rest/v1/distributionsettypes/" + two.getType().getId());
|
||||
|
||||
assertThat(JsonPath.compile("[1]id").read(mvcResult.getResponse().getContentAsString()).toString()).isEqualTo(
|
||||
String.valueOf(two.getId()));
|
||||
assertThat(JsonPath.compile("[1]id").read(mvcResult.getResponse().getContentAsString()).toString())
|
||||
.isEqualTo(String.valueOf(two.getId()));
|
||||
assertThat(
|
||||
JsonPath.compile("[2]_links.self.href").read(mvcResult.getResponse().getContentAsString()).toString())
|
||||
.isEqualTo("http://localhost/rest/v1/distributionsets/" + three.getId());
|
||||
.isEqualTo("http://localhost/rest/v1/distributionsets/" + three.getId());
|
||||
assertThat(
|
||||
JsonPath.compile("[2]_links.type.href").read(mvcResult.getResponse().getContentAsString()).toString())
|
||||
.isEqualTo("http://localhost/rest/v1/distributionsettypes/" + three.getType().getId());
|
||||
.isEqualTo("http://localhost/rest/v1/distributionsettypes/" + three.getType().getId());
|
||||
|
||||
assertThat(JsonPath.compile("[2]id").read(mvcResult.getResponse().getContentAsString()).toString()).isEqualTo(
|
||||
String.valueOf(three.getId()));
|
||||
assertThat(JsonPath.compile("[2]id").read(mvcResult.getResponse().getContentAsString()).toString())
|
||||
.isEqualTo(String.valueOf(three.getId()));
|
||||
|
||||
// check in database
|
||||
assertThat(distributionSetManagement.findDistributionSetsAll(pageReq, false, true)).hasSize(3);
|
||||
@@ -611,7 +574,7 @@ public class DistributionSetResourceTest extends AbstractIntegrationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateDistributionSet() throws Exception {
|
||||
public void updateDistributionSet() throws Exception {
|
||||
|
||||
// prepare test data
|
||||
assertThat(distributionSetManagement.findDistributionSetsAll(pageReq, false, true)).hasSize(0);
|
||||
@@ -626,21 +589,19 @@ public class DistributionSetResourceTest extends AbstractIntegrationTest {
|
||||
update.setName(null);
|
||||
update.setType(standardDsType);
|
||||
|
||||
mvc.perform(
|
||||
put("/rest/v1/distributionsets/{dsId}", set.getId()).content(JsonBuilder.distributionSet(update))
|
||||
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
|
||||
mvc.perform(put("/rest/v1/distributionsets/{dsId}", set.getId()).content(JsonBuilder.distributionSet(update))
|
||||
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
|
||||
|
||||
assertThat(
|
||||
distributionSetManagement.findDistributionSetsAll(pageReq, false, true).getContent().get(0)
|
||||
.getVersion()).isEqualTo("anotherVersion");
|
||||
assertThat(distributionSetManagement.findDistributionSetsAll(pageReq, false, true).getContent().get(0)
|
||||
.getVersion()).isEqualTo("anotherVersion");
|
||||
assertThat(
|
||||
distributionSetManagement.findDistributionSetsAll(pageReq, false, true).getContent().get(0).getName())
|
||||
.isEqualTo(set.getName());
|
||||
.isEqualTo(set.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalidRequestsOnDistributionSetsResource() throws Exception {
|
||||
public void invalidRequestsOnDistributionSetsResource() throws Exception {
|
||||
final DistributionSet set = TestDataUtil.generateDistributionSet("one", softwareManagement,
|
||||
distributionSetManagement);
|
||||
|
||||
@@ -659,15 +620,13 @@ public class DistributionSetResourceTest extends AbstractIntegrationTest {
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isBadRequest());
|
||||
|
||||
// bad request - bad content
|
||||
mvc.perform(
|
||||
post("/rest/v1/distributionsets").content("sdfjsdlkjfskdjf".getBytes()).contentType(
|
||||
MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
|
||||
mvc.perform(post("/rest/v1/distributionsets").content("sdfjsdlkjfskdjf".getBytes())
|
||||
.contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isBadRequest());
|
||||
|
||||
// unsupported media type
|
||||
mvc.perform(
|
||||
post("/rest/v1/distributionsets").content(JsonBuilder.distributionSets(sets)).contentType(
|
||||
MediaType.APPLICATION_OCTET_STREAM)).andDo(MockMvcResultPrinter.print())
|
||||
mvc.perform(post("/rest/v1/distributionsets").content(JsonBuilder.distributionSets(sets))
|
||||
.contentType(MediaType.APPLICATION_OCTET_STREAM)).andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isUnsupportedMediaType());
|
||||
|
||||
// not allowed methods
|
||||
@@ -697,19 +656,18 @@ public class DistributionSetResourceTest extends AbstractIntegrationTest {
|
||||
jsonArray.put(new JSONObject().put("key", knownKey1).put("value", knownValue1));
|
||||
jsonArray.put(new JSONObject().put("key", knownKey2).put("value", knownValue2));
|
||||
|
||||
mvc.perform(
|
||||
post("/rest/v1/distributionsets/{dsId}/metadata", testDS.getId()).contentType(
|
||||
MediaType.APPLICATION_JSON).content(jsonArray.toString())).andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isCreated()).andExpect(content().contentType(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("[0]key", equalTo(knownKey1)))
|
||||
.andExpect(jsonPath("[0]value", equalTo(knownValue1)))
|
||||
mvc.perform(post("/rest/v1/distributionsets/{dsId}/metadata", testDS.getId())
|
||||
.contentType(MediaType.APPLICATION_JSON).content(jsonArray.toString()))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isCreated())
|
||||
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("[0]key", equalTo(knownKey1))).andExpect(jsonPath("[0]value", equalTo(knownValue1)))
|
||||
.andExpect(jsonPath("[1]key", equalTo(knownKey2)))
|
||||
.andExpect(jsonPath("[1]value", equalTo(knownValue2)));
|
||||
|
||||
final DistributionSetMetadata metaKey1 = distributionSetManagement.findOne(new DsMetadataCompositeKey(testDS,
|
||||
knownKey1));
|
||||
final DistributionSetMetadata metaKey2 = distributionSetManagement.findOne(new DsMetadataCompositeKey(testDS,
|
||||
knownKey2));
|
||||
final DistributionSetMetadata metaKey1 = distributionSetManagement
|
||||
.findOne(new DsMetadataCompositeKey(testDS, knownKey1));
|
||||
final DistributionSetMetadata metaKey2 = distributionSetManagement
|
||||
.findOne(new DsMetadataCompositeKey(testDS, knownKey2));
|
||||
|
||||
assertThat(metaKey1.getValue()).isEqualTo(knownValue1);
|
||||
assertThat(metaKey2.getValue()).isEqualTo(knownValue2);
|
||||
@@ -724,19 +682,19 @@ public class DistributionSetResourceTest extends AbstractIntegrationTest {
|
||||
|
||||
final DistributionSet testDS = TestDataUtil.generateDistributionSet("one", softwareManagement,
|
||||
distributionSetManagement);
|
||||
distributionSetManagement.createDistributionSetMetadata(new DistributionSetMetadata(knownKey, testDS,
|
||||
knownValue));
|
||||
distributionSetManagement
|
||||
.createDistributionSetMetadata(new DistributionSetMetadata(knownKey, testDS, knownValue));
|
||||
|
||||
final JSONObject jsonObject = new JSONObject().put("key", knownKey).put("value", updateValue);
|
||||
|
||||
mvc.perform(
|
||||
put("/rest/v1/distributionsets/{dsId}/metadata/{key}", testDS.getId(), knownKey).contentType(
|
||||
MediaType.APPLICATION_JSON).content(jsonObject.toString())).andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON))
|
||||
mvc.perform(put("/rest/v1/distributionsets/{dsId}/metadata/{key}", testDS.getId(), knownKey)
|
||||
.contentType(MediaType.APPLICATION_JSON).content(jsonObject.toString()))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("key", equalTo(knownKey))).andExpect(jsonPath("value", equalTo(updateValue)));
|
||||
|
||||
final DistributionSetMetadata assertDS = distributionSetManagement.findOne(new DsMetadataCompositeKey(testDS,
|
||||
knownKey));
|
||||
final DistributionSetMetadata assertDS = distributionSetManagement
|
||||
.findOne(new DsMetadataCompositeKey(testDS, knownKey));
|
||||
assertThat(assertDS.getValue()).isEqualTo(updateValue);
|
||||
|
||||
}
|
||||
@@ -749,8 +707,8 @@ public class DistributionSetResourceTest extends AbstractIntegrationTest {
|
||||
|
||||
final DistributionSet testDS = TestDataUtil.generateDistributionSet("one", softwareManagement,
|
||||
distributionSetManagement);
|
||||
distributionSetManagement.createDistributionSetMetadata(new DistributionSetMetadata(knownKey, testDS,
|
||||
knownValue));
|
||||
distributionSetManagement
|
||||
.createDistributionSetMetadata(new DistributionSetMetadata(knownKey, testDS, knownValue));
|
||||
|
||||
mvc.perform(delete("/rest/v1/distributionsets/{dsId}/metadata/{key}", testDS.getId(), knownKey))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
|
||||
@@ -770,8 +728,8 @@ public class DistributionSetResourceTest extends AbstractIntegrationTest {
|
||||
final String knownValue = "knownValue";
|
||||
final DistributionSet testDS = TestDataUtil.generateDistributionSet("one", softwareManagement,
|
||||
distributionSetManagement);
|
||||
distributionSetManagement.createDistributionSetMetadata(new DistributionSetMetadata(knownKey, testDS,
|
||||
knownValue));
|
||||
distributionSetManagement
|
||||
.createDistributionSetMetadata(new DistributionSetMetadata(knownKey, testDS, knownValue));
|
||||
|
||||
mvc.perform(get("/rest/v1/distributionsets/{dsId}/metadata/{key}", testDS.getId(), knownKey))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
@@ -793,10 +751,12 @@ public class DistributionSetResourceTest extends AbstractIntegrationTest {
|
||||
distributionSetManagement.findDistributionSetById(testDS.getId()), knownValuePrefix + index));
|
||||
}
|
||||
|
||||
mvc.perform(
|
||||
get("/rest/v1/distributionsets/{dsId}/metadata?offset=" + offsetParam + "&limit=" + limitParam,
|
||||
testDS.getId())).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
.andExpect(jsonPath("size", equalTo(limitParam))).andExpect(jsonPath("total", equalTo(totalMetadata)));
|
||||
mvc.perform(get("/rest/v1/distributionsets/{dsId}/metadata?offset=" + offsetParam + "&limit=" + limitParam,
|
||||
testDS.getId())).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
.andExpect(jsonPath("size", equalTo(limitParam))).andExpect(jsonPath("total", equalTo(totalMetadata)))
|
||||
.andExpect(jsonPath("content[0].key", equalTo("knownKey0")))
|
||||
.andExpect(jsonPath("content[0].value", equalTo("knownValue0")));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -848,10 +808,9 @@ public class DistributionSetResourceTest extends AbstractIntegrationTest {
|
||||
final String rsqlFindTargetId1 = "controllerId==1";
|
||||
|
||||
mvc.perform(
|
||||
get(
|
||||
RestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + createdDs.getId()
|
||||
+ "/assignedTargets?q=" + rsqlFindTargetId1).contentType(MediaType.APPLICATION_JSON)
|
||||
.content(list.toString())).andExpect(status().isOk()).andExpect(jsonPath("total", equalTo(1)))
|
||||
get(RestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + createdDs.getId() + "/assignedTargets?q="
|
||||
+ rsqlFindTargetId1).contentType(MediaType.APPLICATION_JSON).content(list.toString()))
|
||||
.andExpect(status().isOk()).andExpect(jsonPath("total", equalTo(1)))
|
||||
.andExpect(jsonPath("size", equalTo(1))).andExpect(jsonPath("content[0].controllerId", equalTo("1")));
|
||||
}
|
||||
|
||||
@@ -886,19 +845,22 @@ public class DistributionSetResourceTest extends AbstractIntegrationTest {
|
||||
return created;
|
||||
}
|
||||
|
||||
private List<Target> sendUpdateActionStatusToTargets(final DistributionSet dsA, final Iterable<Target> targs,
|
||||
final Status status, final String... msgs) {
|
||||
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<Target>();
|
||||
for (final Target t : targs) {
|
||||
final List<Action> findByTarget = actionRepository.findByTarget(t);
|
||||
for (final Action action : findByTarget) {
|
||||
result.add(sendUpdateActionStatusToTarget(status, action, t, msgs));
|
||||
result.add(sendUpdateActionStatusToTarget(controllerManagament, targetManagement, status, action, t,
|
||||
msgs));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private Target sendUpdateActionStatusToTarget(final Status status, final Action updActA, final Target t,
|
||||
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);
|
||||
|
||||
@@ -913,4 +875,24 @@ public class DistributionSetResourceTest extends AbstractIntegrationTest {
|
||||
return targetManagement.findTargetByControllerID(t.getControllerId());
|
||||
}
|
||||
|
||||
public static DistributionSet createTestDistributionSet(final SoftwareManagement softwareManagement,
|
||||
final DistributionSetManagement distributionSetManagement) {
|
||||
|
||||
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.findDistributionSetsAll(pageReq, false, true)).hasSize(1);
|
||||
return set;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
0
hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/DistributionSetTypeResourceTest.java
Executable file → Normal file
0
hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/DistributionSetTypeResourceTest.java
Executable file → Normal file
0
hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/DownloadResourceTest.java
Executable file → Normal file
0
hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/DownloadResourceTest.java
Executable file → Normal file
183
hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/JsonBuilder.java
Executable file → Normal file
183
hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/JsonBuilder.java
Executable file → Normal file
@@ -58,6 +58,41 @@ public abstract class JsonBuilder {
|
||||
|
||||
}
|
||||
|
||||
public static String softwareModulesCreatableFieldsOnly(final List<SoftwareModule> modules) throws JSONException {
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
|
||||
builder.append("[");
|
||||
int i = 0;
|
||||
for (final SoftwareModule module : modules) {
|
||||
try {
|
||||
builder.append(new JSONObject().put("name", module.getName())
|
||||
.put("description", module.getDescription()).put("type", module.getType().getKey())
|
||||
.put("vendor", module.getVendor()).put("version", module.getVersion()).toString());
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (++i < modules.size()) {
|
||||
builder.append(",");
|
||||
}
|
||||
}
|
||||
|
||||
builder.append("]");
|
||||
|
||||
return builder.toString();
|
||||
|
||||
}
|
||||
|
||||
public static String softwareModuleUpdatableFieldsOnly(final SoftwareModule module) throws JSONException {
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
|
||||
builder.append(new JSONObject().put("description", module.getDescription()).put("vendor", module.getVendor())
|
||||
.toString());
|
||||
|
||||
return builder.toString();
|
||||
|
||||
}
|
||||
|
||||
public static String softwareModuleTypes(final List<SoftwareModuleType> types) throws JSONException {
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
|
||||
@@ -85,9 +120,35 @@ public abstract class JsonBuilder {
|
||||
|
||||
}
|
||||
|
||||
public static String softwareModuleTypesCreatableFieldsOnly(final List<SoftwareModuleType> types)
|
||||
throws JSONException {
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
|
||||
builder.append("[");
|
||||
int i = 0;
|
||||
for (final SoftwareModuleType module : types) {
|
||||
try {
|
||||
builder.append(new JSONObject().put("name", module.getName())
|
||||
.put("description", module.getDescription()).put("key", module.getKey())
|
||||
.put("maxAssignments", module.getMaxAssignments()).toString());
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (++i < types.size()) {
|
||||
builder.append(",");
|
||||
}
|
||||
}
|
||||
|
||||
builder.append("]");
|
||||
|
||||
return builder.toString();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* builds a json string for the feedback for the execution "proceeding".
|
||||
*
|
||||
*
|
||||
* @param id
|
||||
* of the Action feedback refers to
|
||||
* @return the built string
|
||||
@@ -99,7 +160,7 @@ public abstract class JsonBuilder {
|
||||
|
||||
/**
|
||||
* builds a certain json string for a action feedback.
|
||||
*
|
||||
*
|
||||
* @param id
|
||||
* of the action the feedback refers to
|
||||
* @param execution
|
||||
@@ -108,14 +169,20 @@ public abstract class JsonBuilder {
|
||||
* @throws JSONException
|
||||
*/
|
||||
public static String deploymentActionFeedback(final String id, final String execution) throws JSONException {
|
||||
return deploymentActionFeedback(id, execution, "none");
|
||||
return deploymentActionFeedback(id, execution, "none", RandomStringUtils.randomAscii(1000));
|
||||
|
||||
}
|
||||
|
||||
public static String deploymentActionFeedback(final String id, final String execution, final String finished)
|
||||
public static String deploymentActionFeedback(final String id, final String execution, final String message)
|
||||
throws JSONException {
|
||||
return deploymentActionFeedback(id, execution, "none", message);
|
||||
|
||||
}
|
||||
|
||||
public static String deploymentActionFeedback(final String id, final String execution, final String finished,
|
||||
final String message) throws JSONException {
|
||||
final List<String> messages = new ArrayList<String>();
|
||||
messages.add(RandomStringUtils.randomAscii(1000));
|
||||
messages.add(message);
|
||||
|
||||
return new JSONObject().put("id", id).put("time", "20140511T121314")
|
||||
.put("status",
|
||||
@@ -166,6 +233,38 @@ public abstract class JsonBuilder {
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
public static String distributionSetTypesCreateValidFieldsOnly(final List<DistributionSetType> types) {
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
|
||||
builder.append("[");
|
||||
int i = 0;
|
||||
for (final DistributionSetType module : types) {
|
||||
|
||||
try {
|
||||
|
||||
final JSONArray osmTypes = new JSONArray();
|
||||
module.getOptionalModuleTypes().forEach(smt -> osmTypes.put(new JSONObject().put("id", smt.getId())));
|
||||
|
||||
final JSONArray msmTypes = new JSONArray();
|
||||
module.getMandatoryModuleTypes().forEach(smt -> msmTypes.put(new JSONObject().put("id", smt.getId())));
|
||||
|
||||
builder.append(new JSONObject().put("name", module.getName())
|
||||
.put("description", module.getDescription()).put("key", module.getKey())
|
||||
.put("optionalmodules", osmTypes).put("mandatorymodules", msmTypes).toString());
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (++i < types.size()) {
|
||||
builder.append(",");
|
||||
}
|
||||
}
|
||||
|
||||
builder.append("]");
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
public static String distributionSets(final List<DistributionSet> sets) throws JSONException {
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
|
||||
@@ -189,6 +288,64 @@ public abstract class JsonBuilder {
|
||||
|
||||
}
|
||||
|
||||
public static String distributionSetsCreateValidFieldsOnly(final List<DistributionSet> sets) throws JSONException {
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
|
||||
builder.append("[");
|
||||
int i = 0;
|
||||
for (final DistributionSet set : sets) {
|
||||
try {
|
||||
builder.append(distributionSetCreateValidFieldsOnly(set));
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (++i < sets.size()) {
|
||||
builder.append(",");
|
||||
}
|
||||
}
|
||||
|
||||
builder.append("]");
|
||||
|
||||
return builder.toString();
|
||||
|
||||
}
|
||||
|
||||
public static String distributionSetCreateValidFieldsOnly(final DistributionSet set) throws JSONException {
|
||||
|
||||
final List<JSONObject> modules = set.getModules().stream().map(module -> {
|
||||
try {
|
||||
return new JSONObject().put("id", module.getId());
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
return new JSONObject().put("name", set.getName()).put("description", set.getDescription())
|
||||
.put("type", set.getType() == null ? null : set.getType().getKey()).put("version", set.getVersion())
|
||||
.put("requiredMigrationStep", set.isRequiredMigrationStep()).put("modules", modules).toString();
|
||||
|
||||
}
|
||||
|
||||
public static String distributionSetUpdateValidFieldsOnly(final DistributionSet set) throws JSONException {
|
||||
|
||||
final List<JSONObject> modules = set.getModules().stream().map(module -> {
|
||||
try {
|
||||
return new JSONObject().put("id", module.getId());
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
return new JSONObject().put("name", set.getName()).put("description", set.getDescription())
|
||||
.put("version", set.getVersion()).toString();
|
||||
|
||||
}
|
||||
|
||||
public static String distributionSet(final DistributionSet set) throws JSONException {
|
||||
|
||||
final List<JSONObject> modules = set.getModules().stream().map(module -> {
|
||||
@@ -202,10 +359,10 @@ public abstract class JsonBuilder {
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
return new JSONObject().put("name", set.getName()).put("description", set.getDescription())
|
||||
.put("type", set.getType().getKey()).put("id", Long.MAX_VALUE).put("version", set.getVersion())
|
||||
.put("createdAt", "0").put("updatedAt", "0").put("createdBy", "fghdfkjghdfkjh")
|
||||
.put("updatedBy", "fghdfkjghdfkjh").put("requiredMigrationStep", set.isRequiredMigrationStep())
|
||||
.put("modules", modules).toString();
|
||||
.put("type", set.getType() == null ? null : set.getType().getKey()).put("id", Long.MAX_VALUE)
|
||||
.put("version", set.getVersion()).put("createdAt", "0").put("updatedAt", "0")
|
||||
.put("createdBy", "fghdfkjghdfkjh").put("updatedBy", "fghdfkjghdfkjh")
|
||||
.put("requiredMigrationStep", set.isRequiredMigrationStep()).put("modules", modules).toString();
|
||||
|
||||
}
|
||||
|
||||
@@ -239,8 +396,14 @@ public abstract class JsonBuilder {
|
||||
}
|
||||
|
||||
public static String cancelActionFeedback(final String id, final String execution) throws JSONException {
|
||||
return cancelActionFeedback(id, execution, RandomStringUtils.randomAscii(1000));
|
||||
|
||||
}
|
||||
|
||||
public static String cancelActionFeedback(final String id, final String execution, final String message)
|
||||
throws JSONException {
|
||||
final List<String> messages = new ArrayList<String>();
|
||||
messages.add(RandomStringUtils.randomAscii(1000));
|
||||
messages.add(message);
|
||||
return new JSONObject().put("id", id).put("time", "20140511T121314")
|
||||
.put("status",
|
||||
new JSONObject().put("execution", execution)
|
||||
|
||||
0
hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/RSQLUtilityTest.java
Executable file → Normal file
0
hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/RSQLUtilityTest.java
Executable file → Normal file
0
hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/ResourceUtility.java
Executable file → Normal file
0
hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/ResourceUtility.java
Executable file → Normal file
0
hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/SMRessourceMisingMongoDbConnectionTest.java
Executable file → Normal file
0
hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/SMRessourceMisingMongoDbConnectionTest.java
Executable file → Normal file
119
hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/SoftwareModuleResourceTest.java
Executable file → Normal file
119
hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/SoftwareModuleResourceTest.java
Executable file → Normal file
@@ -64,16 +64,14 @@ import ru.yandex.qatools.allure.annotations.Stories;
|
||||
/**
|
||||
* Tests for {@link SoftwareModuleResource} {@link RestController}.
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
@Features("Component Tests - Management RESTful API")
|
||||
@Stories("Software Module Resource")
|
||||
// TODO: fully document tests -> @Description for long text and reasonable
|
||||
// method name as short text
|
||||
public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongoDB {
|
||||
|
||||
@Test
|
||||
@Description("Tests the update of software module metadata. It is verfied that only the selected fields for the update are really updated and the modification values are filled (i.e. updated by and at).")
|
||||
@WithUser(principal = "smUpdateTester", allSpPermissions = true)
|
||||
public void updateSoftwareModuleOnlyDescriptionAndVendorNameUntouched() throws Exception {
|
||||
final String knownSWName = "name1";
|
||||
final String knownSWVersion = "version1";
|
||||
@@ -99,10 +97,16 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo
|
||||
final String body = new JSONObject().put("vendor", updateVendor).put("description", updateDescription)
|
||||
.put("name", "nameShouldNotBeChanged").toString();
|
||||
|
||||
// ensures that we are not to fast so that last modified is not set
|
||||
// correctly
|
||||
Thread.sleep(1);
|
||||
|
||||
mvc.perform(put("/rest/v1/softwaremodules/{smId}", sm.getId()).content(body)
|
||||
.contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$id", equalTo(sm.getId().intValue())))
|
||||
.andExpect(jsonPath("$vendor", equalTo(updateVendor)))
|
||||
.andExpect(jsonPath("$lastModifiedBy", equalTo("smUpdateTester")))
|
||||
.andExpect(jsonPath("$lastModifiedAt", not(equalTo(sm.getLastModifiedAt()))))
|
||||
.andExpect(jsonPath("$description", equalTo(updateDescription)))
|
||||
.andExpect(jsonPath("$name", equalTo(knownSWName))).andReturn();
|
||||
|
||||
@@ -112,12 +116,13 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo
|
||||
* Test method for
|
||||
* {@link org.eclipse.hawkbit.rest.resource.SoftwareModuleResource#uploadArtifact(java.lang.Long, org.springframework.web.multipart.MultipartFile)}
|
||||
* .
|
||||
*
|
||||
*
|
||||
* @throws Exception
|
||||
* if test fails
|
||||
*/
|
||||
@Test
|
||||
public void testUploadArtifact() throws Exception {
|
||||
@Description("Tests the uppload of an artifact binary. The upload is executed and the content checked in the repository for completenes.")
|
||||
public void uploadArtifact() throws Exception {
|
||||
// prepare repo
|
||||
assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(0);
|
||||
assertThat(artifactRepository.findAll()).hasSize(0);
|
||||
@@ -139,6 +144,7 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo
|
||||
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("$type", equalTo("local"))).andExpect(jsonPath("$hashes.md5", equalTo(md5sum)))
|
||||
.andExpect(jsonPath("$hashes.sha1", equalTo(sha1sum)))
|
||||
.andExpect(jsonPath("$size", equalTo(random.length)))
|
||||
.andExpect(jsonPath("$providedFilename", equalTo("origFilename"))).andReturn();
|
||||
|
||||
// check rest of response compared to DB
|
||||
@@ -179,7 +185,8 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmptyUploadArtifact() throws Exception {
|
||||
@Description("Verfies that the system does not accept empty artifact uploads. Expected response: BAD REQUEST")
|
||||
public void emptyUploadArtifact() throws Exception {
|
||||
assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(0);
|
||||
assertThat(artifactRepository.findAll()).hasSize(0);
|
||||
|
||||
@@ -194,7 +201,8 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDuplicateUploadArtifact() throws Exception {
|
||||
@Description("Verfies that the system does not accept identical artifacts uploads for the same software module. Expected response: CONFLICT")
|
||||
public void duplicateUploadArtifact() throws Exception {
|
||||
assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(0);
|
||||
assertThat(artifactRepository.findAll()).hasSize(0);
|
||||
|
||||
@@ -218,7 +226,8 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUploadArtifactWithCustomName() throws Exception {
|
||||
@Description("verfies that option to upload artifacts with a custom defined by metadata, i.e. not the file name of the binary itself.")
|
||||
public void uploadArtifactWithCustomName() throws Exception {
|
||||
// prepare repo
|
||||
assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(0);
|
||||
assertThat(artifactRepository.findAll()).hasSize(0);
|
||||
@@ -247,7 +256,8 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUploadArtifactWithHashCheck() throws Exception {
|
||||
@Description("Verfies that the system refuses upload of an artifact where the provided hash sums do not match. Expected result: BAD REQUEST")
|
||||
public void uploadArtifactWithHashCheck() throws Exception {
|
||||
// prepare repo
|
||||
assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(0);
|
||||
assertThat(artifactRepository.findAll()).hasSize(0);
|
||||
@@ -310,16 +320,9 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.eclipse.hawkbit.rest.resource.SoftwareModuleResource#downloadArtifact(java.lang.Long, javax.servlet.http.HttpServletResponse)}
|
||||
* .
|
||||
*
|
||||
* @throws Exception
|
||||
* if test fails
|
||||
*/
|
||||
@Test
|
||||
public void testDownloadArtifact() throws Exception {
|
||||
@Description("Tests binary download of an artifact including verfication that the downloaded binary is consistent and that the etag header is as expected identical to the SHA1 hash of the file.")
|
||||
public void downloadArtifact() throws Exception {
|
||||
assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(0);
|
||||
assertThat(artifactRepository.findAll()).hasSize(0);
|
||||
|
||||
@@ -336,13 +339,16 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo
|
||||
final MvcResult result = mvc
|
||||
.perform(
|
||||
get("/rest/v1/softwaremodules/{smId}/artifacts/{artId}/download", sm.getId(), artifact.getId()))
|
||||
.andExpect(header().string("ETag", artifact.getSha1Hash())).andReturn();
|
||||
.andExpect(header().string("ETag", artifact.getSha1Hash()))
|
||||
.andExpect(content().contentType(MediaType.APPLICATION_OCTET_STREAM)).andReturn();
|
||||
|
||||
assertTrue(Arrays.equals(result.getResponse().getContentAsByteArray(), random));
|
||||
|
||||
final MvcResult result2 = mvc.perform(
|
||||
get("/rest/v1/softwaremodules/{smId}/artifacts/{artId}/download", sm.getId(), artifact2.getId()))
|
||||
.andExpect(header().string("ETag", artifact2.getSha1Hash())).andReturn();
|
||||
final MvcResult result2 = mvc
|
||||
.perform(get("/rest/v1/softwaremodules/{smId}/artifacts/{artId}/download", sm.getId(),
|
||||
artifact2.getId()))
|
||||
.andExpect(header().string("ETag", artifact2.getSha1Hash()))
|
||||
.andExpect(content().contentType(MediaType.APPLICATION_OCTET_STREAM)).andReturn();
|
||||
|
||||
assertTrue(Arrays.equals(result2.getResponse().getContentAsByteArray(), random));
|
||||
|
||||
@@ -351,7 +357,8 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetArtifact() throws Exception {
|
||||
@Description("Verifies the listing of one defined artifact assigned to a given software module. That includes the artifact metadata and download links.")
|
||||
public void getArtifact() throws Exception {
|
||||
// check baseline
|
||||
assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(0);
|
||||
assertThat(artifactRepository.findAll()).hasSize(0);
|
||||
@@ -381,7 +388,8 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetArtifacts() throws Exception {
|
||||
@Description("Verifies the listing of all artifacts assigned to a software module. That includes the artifact metadata and download links.")
|
||||
public void getArtifacts() throws Exception {
|
||||
SoftwareModule sm = new SoftwareModule(osType, "name 1", "version 1", null, null);
|
||||
sm = softwareManagement.createSoftwareModule(sm);
|
||||
|
||||
@@ -420,7 +428,8 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalidRequestsOnArtifactResource() throws Exception {
|
||||
@Description("Verfies that the system refuses unsupported request types and answers as defined to them, e.g. NOT FOUND on a non existing resource. Or a HTTP POST for updating a resource results in METHOD NOT ALLOWED etc.")
|
||||
public void invalidRequestsOnArtifactResource() throws Exception {
|
||||
final byte random[] = RandomStringUtils.random(5 * 1024).getBytes();
|
||||
final MockMultipartFile file = new MockMultipartFile("file", "orig", null, random);
|
||||
|
||||
@@ -455,7 +464,8 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalidRequestsOnSoftwaremodulesResource() throws Exception {
|
||||
@Description("Verfies that the system refuses unsupported request types and answers as defined to them, e.g. NOT FOUND on a non existing resource. Or a HTTP POST for updating a resource results in METHOD NOT ALLOWED etc.")
|
||||
public void invalidRequestsOnSoftwaremodulesResource() throws Exception {
|
||||
SoftwareModule sm = new SoftwareModule(osType, "name 1", "version 1", null, null);
|
||||
sm = softwareManagement.createSoftwareModule(sm);
|
||||
|
||||
@@ -493,7 +503,8 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSoftwareModulesWithoutAddtionalRequestParameters() throws Exception {
|
||||
@Description("Test of modules retrieval without any parameters. Will return all modules in the system as defined by standard page size.")
|
||||
public void getSoftwareModulesWithoutAddtionalRequestParameters() throws Exception {
|
||||
final int modules = 5;
|
||||
createSoftwareModulesAlphabetical(modules);
|
||||
mvc.perform(get(RestConstants.SOFTWAREMODULE_V1_REQUEST_MAPPING)).andDo(MockMvcResultPrinter.print())
|
||||
@@ -504,7 +515,8 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSoftwareModulesWithPagingLimitRequestParameter() throws Exception {
|
||||
@Description("Test of modules retrieval with paging limit parameter. Will return all modules in the system as defined by given page size.")
|
||||
public void detSoftwareModulesWithPagingLimitRequestParameter() throws Exception {
|
||||
final int modules = 5;
|
||||
final int limitSize = 1;
|
||||
createSoftwareModulesAlphabetical(modules);
|
||||
@@ -517,7 +529,8 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSoftwareModulesWithPagingLimitAndOffsetRequestParameter() throws Exception {
|
||||
@Description("Test of modules retrieval with paging limit offset parameters. Will return all modules in the system as defined by given page size starting from given offset.")
|
||||
public void getSoftwareModulesWithPagingLimitAndOffsetRequestParameter() throws Exception {
|
||||
final int modules = 5;
|
||||
final int offsetParam = 2;
|
||||
final int expectedSize = modules - offsetParam;
|
||||
@@ -533,7 +546,8 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo
|
||||
|
||||
@Test
|
||||
@WithUser(principal = "uploadTester", allSpPermissions = true)
|
||||
public void testGetSoftwareModules() throws Exception {
|
||||
@Description("Test retrieval of all software modules the user has access to.")
|
||||
public void getSoftwareModules() throws Exception {
|
||||
assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(0);
|
||||
|
||||
SoftwareModule os = new SoftwareModule(osType, "name1", "version1", "description1", "vendor1");
|
||||
@@ -559,6 +573,11 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo
|
||||
equalTo("http://localhost/rest/v1/softwaremoduletypes/" + osType.getId())))
|
||||
.andExpect(jsonPath("$content.[?(@.id==" + os.getId() + ")][0]._links.self.href",
|
||||
equalTo("http://localhost/rest/v1/softwaremodules/" + os.getId())))
|
||||
.andExpect(jsonPath("$content.[?(@.id==" + os.getId() + ")][0]._links.artifacts.href",
|
||||
equalTo("http://localhost/rest/v1/softwaremodules/" + os.getId() + "/artifacts")))
|
||||
.andExpect(jsonPath("$content.[?(@.id==" + os.getId() + ")][0]._links.metadata.href",
|
||||
equalTo("http://localhost/rest/v1/softwaremodules/" + os.getId()
|
||||
+ "/metadata?offset=0&limit=50")))
|
||||
.andExpect(jsonPath("$content.[?(@.id==" + jvm.getId() + ")][0].name", equalTo("name1")))
|
||||
.andExpect(jsonPath("$content.[?(@.id==" + jvm.getId() + ")][0].version", equalTo("version1")))
|
||||
.andExpect(jsonPath("$content.[?(@.id==" + jvm.getId() + ")][0].description", equalTo("description1")))
|
||||
@@ -571,6 +590,11 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo
|
||||
equalTo("http://localhost/rest/v1/softwaremoduletypes/" + runtimeType.getId())))
|
||||
.andExpect(jsonPath("$content.[?(@.id==" + jvm.getId() + ")][0]._links.self.href",
|
||||
equalTo("http://localhost/rest/v1/softwaremodules/" + jvm.getId())))
|
||||
.andExpect(jsonPath("$content.[?(@.id==" + jvm.getId() + ")][0]._links.artifacts.href",
|
||||
equalTo("http://localhost/rest/v1/softwaremodules/" + jvm.getId() + "/artifacts")))
|
||||
.andExpect(jsonPath("$content.[?(@.id==" + jvm.getId() + ")][0]._links.metadata.href",
|
||||
equalTo("http://localhost/rest/v1/softwaremodules/" + jvm.getId()
|
||||
+ "/metadata?offset=0&limit=50")))
|
||||
.andExpect(jsonPath("$content.[?(@.id==" + ah.getId() + ")][0].name", equalTo("name1")))
|
||||
.andExpect(jsonPath("$content.[?(@.id==" + ah.getId() + ")][0].version", equalTo("version1")))
|
||||
.andExpect(jsonPath("$content.[?(@.id==" + ah.getId() + ")][0].description", equalTo("description1")))
|
||||
@@ -578,6 +602,11 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo
|
||||
.andExpect(jsonPath("$content.[?(@.id==" + ah.getId() + ")][0].type", equalTo("application")))
|
||||
.andExpect(jsonPath("$content.[?(@.id==" + ah.getId() + ")][0].createdBy", equalTo("uploadTester")))
|
||||
.andExpect(jsonPath("$content.[?(@.id==" + ah.getId() + ")][0].createdAt", equalTo(ah.getCreatedAt())))
|
||||
.andExpect(jsonPath("$content.[?(@.id==" + ah.getId() + ")][0]._links.artifacts.href",
|
||||
equalTo("http://localhost/rest/v1/softwaremodules/" + ah.getId() + "/artifacts")))
|
||||
.andExpect(jsonPath("$content.[?(@.id==" + ah.getId() + ")][0]._links.metadata.href",
|
||||
equalTo("http://localhost/rest/v1/softwaremodules/" + ah.getId()
|
||||
+ "/metadata?offset=0&limit=50")))
|
||||
.andExpect(jsonPath("$content.[?(@.id==" + ah.getId() + ")][0]._links.type.href",
|
||||
equalTo("http://localhost/rest/v1/softwaremoduletypes/" + appType.getId())))
|
||||
.andExpect(jsonPath("$content.[?(@.id==" + ah.getId() + ")][0]._links.self.href",
|
||||
@@ -587,7 +616,8 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSoftwareModulesWithFilterParameters() throws Exception {
|
||||
@Description("Test the various filter parameters, e.g. filter by name or type of the module.")
|
||||
public void getSoftwareModulesWithFilterParameters() throws Exception {
|
||||
assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(0);
|
||||
|
||||
SoftwareModule os1 = new SoftwareModule(osType, "osName1", "1.0.0", "description1", "vendor1");
|
||||
@@ -663,14 +693,16 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSoftwareModulesWithSyntaxErrorFilterParameter() throws Exception {
|
||||
@Description("Verfies that the system answers as defined in case of a wrong filter parameter syntax. Expected result: BAD REQUEST with error description.")
|
||||
public void getSoftwareModulesWithSyntaxErrorFilterParameter() throws Exception {
|
||||
mvc.perform(get("/rest/v1/softwaremodules?q=wrongFIQLSyntax").accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isBadRequest())
|
||||
.andExpect(jsonPath("$errorCode", equalTo("hawkbit.server.error.rest.param.rsqlParamSyntax")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSoftwareModulesWithUnknownFieldErrorFilterParameter() throws Exception {
|
||||
@Description("Verfies that the system answers as defined in case of a wnon extsing field used in filter. Expected result: BAD REQUEST with error description.")
|
||||
public void getSoftwareModulesWithUnknownFieldErrorFilterParameter() throws Exception {
|
||||
mvc.perform(get("/rest/v1/softwaremodules?q=wrongField==abc").accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isBadRequest())
|
||||
.andExpect(jsonPath("$errorCode", equalTo("hawkbit.server.error.rest.param.rsqlInvalidField")));
|
||||
@@ -693,6 +725,9 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo
|
||||
.andExpect(jsonPath("$vendor", equalTo("vendor1"))).andExpect(jsonPath("$type", equalTo("os")))
|
||||
.andExpect(jsonPath("$createdBy", equalTo("uploadTester")))
|
||||
.andExpect(jsonPath("$createdAt", equalTo(os.getCreatedAt())))
|
||||
.andExpect(jsonPath("$_links.metadata.href",
|
||||
equalTo("http://localhost/rest/v1/softwaremodules/" + os.getId()
|
||||
+ "/metadata?offset=0&limit=50")))
|
||||
.andExpect(jsonPath("$_links.type.href",
|
||||
equalTo("http://localhost/rest/v1/softwaremoduletypes/" + osType.getId())))
|
||||
.andExpect(jsonPath("$_links.artifacts.href",
|
||||
@@ -709,6 +744,9 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo
|
||||
.andExpect(jsonPath("$vendor", equalTo("vendor1"))).andExpect(jsonPath("$type", equalTo("runtime")))
|
||||
.andExpect(jsonPath("$createdBy", equalTo("uploadTester")))
|
||||
.andExpect(jsonPath("$createdAt", equalTo(jvm.getCreatedAt())))
|
||||
.andExpect(jsonPath("$_links.metadata.href",
|
||||
equalTo("http://localhost/rest/v1/softwaremodules/" + jvm.getId()
|
||||
+ "/metadata?offset=0&limit=50")))
|
||||
.andExpect(jsonPath("$_links.type.href",
|
||||
equalTo("http://localhost/rest/v1/softwaremoduletypes/" + runtimeType.getId())))
|
||||
.andExpect(jsonPath("$_links.artifacts.href",
|
||||
@@ -725,6 +763,9 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo
|
||||
.andExpect(jsonPath("$vendor", equalTo("vendor1"))).andExpect(jsonPath("$type", equalTo("application")))
|
||||
.andExpect(jsonPath("$createdBy", equalTo("uploadTester")))
|
||||
.andExpect(jsonPath("$createdAt", equalTo(ah.getCreatedAt())))
|
||||
.andExpect(jsonPath("$_links.metadata.href",
|
||||
equalTo("http://localhost/rest/v1/softwaremodules/" + ah.getId()
|
||||
+ "/metadata?offset=0&limit=50")))
|
||||
.andExpect(jsonPath("$_links.type.href",
|
||||
equalTo("http://localhost/rest/v1/softwaremoduletypes/" + appType.getId())))
|
||||
.andExpect(jsonPath("$_links.artifacts.href",
|
||||
@@ -735,6 +776,7 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo
|
||||
|
||||
@Test
|
||||
@WithUser(principal = "uploadTester", allSpPermissions = true)
|
||||
@Description("Verfies that the create request actually results in the creation of the modules in the repository.")
|
||||
public void createSoftwareModules() throws JSONException, Exception {
|
||||
assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(0);
|
||||
|
||||
@@ -812,6 +854,7 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verifies successfull deletion of software modules that are not in use, i.e. assigned to a DS.")
|
||||
public void deleteUnassignedSoftwareModule() throws Exception {
|
||||
assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).isEmpty();
|
||||
assertThat(artifactRepository.findAll()).isEmpty();
|
||||
@@ -837,6 +880,7 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verifies successfull deletion of software modules that are in use, i.e. assigned to a DS which should result in movinf the module to the archive.")
|
||||
public void deleteAssignedSoftwareModule() throws Exception {
|
||||
// check baseline
|
||||
assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).isEmpty();
|
||||
@@ -868,7 +912,8 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteArtifact() throws Exception {
|
||||
@Description("Tests the deletion of an artifact including verfication that the artifact is actually erased in the repository and removed from the software module.")
|
||||
public void deleteArtifact() throws Exception {
|
||||
assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).isEmpty();
|
||||
assertThat(artifactRepository.findAll()).isEmpty();
|
||||
|
||||
@@ -902,6 +947,7 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verfies the successfull creation of metadata.")
|
||||
public void createMetadata() throws Exception {
|
||||
|
||||
final String knownKey1 = "knownKey1";
|
||||
@@ -931,6 +977,7 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verfies the successfull update of metadata based on given key.")
|
||||
public void updateMetadata() throws Exception {
|
||||
// prepare and create metadata for update
|
||||
final String knownKey = "knownKey";
|
||||
@@ -954,6 +1001,7 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verfies the successfull deletion of metadata entry.")
|
||||
public void deleteMetadata() throws Exception {
|
||||
// prepare and create metadata for deletion
|
||||
final String knownKey = "knownKey";
|
||||
@@ -975,6 +1023,7 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verfies the successfull search of a metadata entry based on value.")
|
||||
public void searchSoftwareModuleMetadataRsql() throws Exception {
|
||||
final int totalMetadata = 10;
|
||||
final String knownKeyPrefix = "knownKey";
|
||||
|
||||
0
hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/SoftwareModuleTypeResourceTest.java
Executable file → Normal file
0
hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/SoftwareModuleTypeResourceTest.java
Executable file → Normal file
0
hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/SortUtilityTest.java
Executable file → Normal file
0
hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/SortUtilityTest.java
Executable file → Normal file
100
hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/SystemManagementResourceTest.java
Executable file → Normal file
100
hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/SystemManagementResourceTest.java
Executable file → Normal file
@@ -9,17 +9,28 @@
|
||||
package org.eclipse.hawkbit.rest.resource;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
import org.eclipse.hawkbit.AbstractIntegrationTest;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import org.eclipse.hawkbit.AbstractIntegrationTestWithMongoDB;
|
||||
import org.eclipse.hawkbit.MockMvcResultPrinter;
|
||||
import org.eclipse.hawkbit.TestDataUtil;
|
||||
import org.eclipse.hawkbit.WithSpringAuthorityRule;
|
||||
import org.eclipse.hawkbit.WithUser;
|
||||
import org.eclipse.hawkbit.im.authentication.SpPermission;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.junit.Test;
|
||||
import org.springframework.http.MediaType;
|
||||
|
||||
import ru.yandex.qatools.allure.annotations.Description;
|
||||
import ru.yandex.qatools.allure.annotations.Features;
|
||||
@@ -31,7 +42,37 @@ import ru.yandex.qatools.allure.annotations.Stories;
|
||||
*/
|
||||
@Features("Component Tests - System Management RESTful API")
|
||||
@Stories("System Management Resource")
|
||||
public class SystemManagementResourceTest extends AbstractIntegrationTest {
|
||||
public class SystemManagementResourceTest extends AbstractIntegrationTestWithMongoDB {
|
||||
|
||||
@Test
|
||||
@WithUser(tenantId = "mytenant", authorities = { SpPermission.SYSTEM_ADMIN })
|
||||
@Description("Tests that the system is able to collect statistics for the entire system.")
|
||||
public void collectSystemStatistics() throws Exception {
|
||||
createTestTenantsForSystemStatistics(2, 2000, 100, 2);
|
||||
|
||||
mvc.perform(get("/system/admin/usage").accept(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("$tenantStats.[?(@.tenantName==tenant0)][0].targets", equalTo(100)))
|
||||
.andExpect(jsonPath("$tenantStats.[?(@.tenantName==tenant0)][0].overallArtifactVolumeInBytes",
|
||||
equalTo(2000)))
|
||||
.andExpect(jsonPath("$tenantStats.[?(@.tenantName==tenant0)][0].artifacts", equalTo(1)))
|
||||
.andExpect(jsonPath("$tenantStats.[?(@.tenantName==tenant0)][0].actions", equalTo(200)))
|
||||
.andExpect(jsonPath("$overallTargets", equalTo(200)))
|
||||
.andExpect(jsonPath("$overallArtifacts", equalTo(2)))
|
||||
.andExpect(jsonPath("$overallArtifactVolumeInBytes", equalTo(4000)))
|
||||
.andExpect(jsonPath("$overallActions", equalTo(400)))
|
||||
.andExpect(jsonPath("$overallTenants", equalTo(4)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@WithUser(tenantId = "mytenant", authorities = { SpPermission.DELETE_TARGET, SpPermission.DELETE_REPOSITORY,
|
||||
SpPermission.CREATE_REPOSITORY, SpPermission.READ_REPOSITORY })
|
||||
@Description("Tests that the system is not able to collect statistics for the entire system if the .")
|
||||
public void collectSystemStatisticsWithMissingPermissionFails() throws Exception {
|
||||
|
||||
mvc.perform(get("/system/admin/usage").accept(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isForbidden());
|
||||
}
|
||||
|
||||
@Test
|
||||
@WithUser(tenantId = "mytenant", allSpPermissions = true)
|
||||
@@ -76,4 +117,59 @@ public class SystemManagementResourceTest extends AbstractIntegrationTest {
|
||||
mvc.perform(delete("/system/admin/caches")).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
|
||||
}
|
||||
|
||||
private byte[] createTestTenantsForSystemStatistics(final int tenants, final int artifactSize, final int targets,
|
||||
final int updates) throws Exception {
|
||||
final Random randomgen = new Random();
|
||||
final byte random[] = new byte[artifactSize];
|
||||
randomgen.nextBytes(random);
|
||||
|
||||
for (int i = 0; i < tenants; i++) {
|
||||
final String tenantname = "tenant" + i;
|
||||
securityRule.runAs(WithSpringAuthorityRule.withUserAndTenant("bumlux", tenantname), () -> {
|
||||
systemManagement.getTenantMetadata(tenantname);
|
||||
if (artifactSize > 0) {
|
||||
createTestArtifact(random);
|
||||
createDeletedTestArtifact(random);
|
||||
}
|
||||
if (targets > 0) {
|
||||
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);
|
||||
|
||||
deploymentManagement.assignDistributionSet(ds, createdTargets);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
return random;
|
||||
}
|
||||
|
||||
private List<Target> createTestTargets(final int targets) {
|
||||
return targetManagement
|
||||
.createTargets(TestDataUtil.buildTargetFixtures(targets, "testTargetOfTenant", "testTargetOfTenant"));
|
||||
}
|
||||
|
||||
private void createTestArtifact(final byte[] random) {
|
||||
SoftwareModule sm = new SoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), "name 1",
|
||||
"version 1", null, null);
|
||||
sm = softwareModuleRepository.save(sm);
|
||||
|
||||
artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), sm.getId(), "file1", false);
|
||||
}
|
||||
|
||||
private void createDeletedTestArtifact(final byte[] random) {
|
||||
final DistributionSet ds = TestDataUtil.generateDistributionSet("deleted garbage", softwareManagement,
|
||||
distributionSetManagement, true);
|
||||
ds.getModules().stream().forEach(module -> {
|
||||
artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), module.getId(), "file1", false);
|
||||
softwareManagement.deleteSoftwareModule(module);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
82
hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/TargetResourceTest.java
Executable file → Normal file
82
hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/TargetResourceTest.java
Executable file → Normal file
@@ -61,6 +61,7 @@ import org.springframework.test.web.servlet.MvcResult;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.jayway.jsonpath.JsonPath;
|
||||
|
||||
import ru.yandex.qatools.allure.annotations.Description;
|
||||
import ru.yandex.qatools.allure.annotations.Features;
|
||||
import ru.yandex.qatools.allure.annotations.Stories;
|
||||
|
||||
@@ -228,24 +229,14 @@ public class TargetResourceTest extends AbstractIntegrationTest {
|
||||
@Test
|
||||
public void cancelActionOK() throws Exception {
|
||||
// prepare test
|
||||
final DistributionSet dsA = TestDataUtil.generateDistributionSet("", softwareManagement,
|
||||
distributionSetManagement);
|
||||
;
|
||||
final Target tA = targetManagement
|
||||
.createTarget(TestDataUtil.buildTargetFixture("target-id-A", "first description"));
|
||||
// assign a distribution set so we get an active update action
|
||||
deploymentManagement.assignDistributionSet(dsA, Lists.newArrayList(tA));
|
||||
|
||||
// verify active action
|
||||
final Slice<Action> actionsByTarget = deploymentManagement.findActionsByTarget(new PageRequest(0, 100), tA);
|
||||
assertThat(actionsByTarget.getContent()).hasSize(1);
|
||||
Target tA = createTargetAndStartAction();
|
||||
|
||||
// test - cancel the active action
|
||||
mvc.perform(delete(RestConstants.TARGET_V1_REQUEST_MAPPING + "/{targetId}/actions/{actionId}",
|
||||
tA.getControllerId(), actionsByTarget.getContent().get(0).getId())).andDo(MockMvcResultPrinter.print())
|
||||
tA.getControllerId(), tA.getActions().get(0).getId())).andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isNoContent());
|
||||
|
||||
final Action action = deploymentManagement.findAction(actionsByTarget.getContent().get(0).getId());
|
||||
final Action action = deploymentManagement.findAction(tA.getActions().get(0).getId());
|
||||
// still active because in "canceling" state and waiting for controller
|
||||
// feedback
|
||||
assertThat(action.isActive()).isTrue();
|
||||
@@ -261,18 +252,10 @@ public class TargetResourceTest extends AbstractIntegrationTest {
|
||||
@Test
|
||||
public void cancelAnCancelActionIsNotAllowed() throws Exception {
|
||||
// prepare test
|
||||
final DistributionSet dsA = TestDataUtil.generateDistributionSet("", softwareManagement,
|
||||
distributionSetManagement);
|
||||
;
|
||||
Target tA = targetManagement.createTarget(TestDataUtil.buildTargetFixture("target-id-A", "first description"));
|
||||
// assign a distribution set so we get an active update action
|
||||
deploymentManagement.assignDistributionSet(dsA, Lists.newArrayList(tA));
|
||||
// verify active action
|
||||
final Slice<Action> actionsByTarget = deploymentManagement.findActionsByTarget(new PageRequest(0, 100), tA);
|
||||
assertThat(actionsByTarget.getContent()).hasSize(1);
|
||||
Target tA = createTargetAndStartAction();
|
||||
|
||||
// cancel the active action
|
||||
tA = targetManagement.findTargetByControllerID(tA.getControllerId());
|
||||
deploymentManagement.cancelAction(actionsByTarget.getContent().get(0), tA);
|
||||
deploymentManagement.cancelAction(tA.getActions().get(0), tA);
|
||||
|
||||
// find the current active action
|
||||
final List<Action> cancelActions = deploymentManagement.findActionsByTarget(new PageRequest(0, 100), tA)
|
||||
@@ -285,6 +268,39 @@ public class TargetResourceTest extends AbstractIntegrationTest {
|
||||
.andExpect(status().isMethodNotAllowed());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Force Quit an Action, which is already canceled. Expected Result is an HTTP response code 204.")
|
||||
public void forceQuitAnCanceledActionReturnsOk() throws Exception {
|
||||
|
||||
Target tA = createTargetAndStartAction();
|
||||
|
||||
// cancel the active action
|
||||
deploymentManagement.cancelAction(tA.getActions().get(0), tA);
|
||||
|
||||
// find the current active action
|
||||
final List<Action> cancelActions = deploymentManagement.findActionsByTarget(new PageRequest(0, 100), tA)
|
||||
.getContent().stream().filter(action -> action.isCancelingOrCanceled()).collect(Collectors.toList());
|
||||
assertThat(cancelActions).hasSize(1);
|
||||
assertThat(cancelActions.get(0).isCancelingOrCanceled()).isTrue();
|
||||
|
||||
// test - force quit an canceled action should return 204
|
||||
mvc.perform(delete(RestConstants.TARGET_V1_REQUEST_MAPPING + "/{targetId}/actions/{actionId}?force=true",
|
||||
tA.getControllerId(), cancelActions.get(0).getId())).andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isNoContent());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Force Quit an Action, which is not canceled. Expected Result is an HTTP response code 405.")
|
||||
public void forceQuitAnNotCanceledActionReturnsMethodNotAllowed() throws Exception {
|
||||
|
||||
Target tA = createTargetAndStartAction();
|
||||
|
||||
// test - cancel an cancel action returns forbidden
|
||||
mvc.perform(delete(RestConstants.TARGET_V1_REQUEST_MAPPING + "/{targetId}/actions/{actionId}?force=true",
|
||||
tA.getControllerId(), tA.getActions().get(0).getId())).andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isMethodNotAllowed());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deleteTargetReturnsOK() throws Exception {
|
||||
final String knownControllerId = "knownControllerIdDelete";
|
||||
@@ -1206,4 +1222,22 @@ public class TargetResourceTest extends AbstractIntegrationTest {
|
||||
final ActionStatus actionStatus = new ActionStatus(action, Status.FINISHED, 0l);
|
||||
controllerManagement.addUpdateActionStatus(actionStatus, action);
|
||||
}
|
||||
|
||||
/**
|
||||
* helper method to create a target and start an action on it.
|
||||
*
|
||||
* @return The targetid of the created target.
|
||||
*/
|
||||
private Target createTargetAndStartAction() {
|
||||
// prepare test
|
||||
final DistributionSet dsA = TestDataUtil.generateDistributionSet("", softwareManagement,
|
||||
distributionSetManagement);
|
||||
Target tA = targetManagement.createTarget(TestDataUtil.buildTargetFixture("target-id-A", "first description"));
|
||||
// assign a distribution set so we get an active update action
|
||||
deploymentManagement.assignDistributionSet(dsA, Lists.newArrayList(tA));
|
||||
// verify active action
|
||||
final Slice<Action> actionsByTarget = deploymentManagement.findActionsByTarget(new PageRequest(0, 100), tA);
|
||||
assertThat(actionsByTarget.getContent()).hasSize(1);
|
||||
return targetManagement.findTargetByControllerID(tA.getControllerId());
|
||||
}
|
||||
}
|
||||
|
||||
0
hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/model/ExceptionInfoTest.java
Executable file → Normal file
0
hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/model/ExceptionInfoTest.java
Executable file → Normal file
0
hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/model/PagedListTest.java
Executable file → Normal file
0
hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/model/PagedListTest.java
Executable file → Normal file
0
hawkbit-rest-resource/src/test/resources/application-test.properties
Executable file → Normal file
0
hawkbit-rest-resource/src/test/resources/application-test.properties
Executable file → Normal file
26
hawkbit-rest-resource/src/test/resources/log4j2.xml
Normal file
26
hawkbit-rest-resource/src/test/resources/log4j2.xml
Normal file
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
|
||||
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
|
||||
|
||||
-->
|
||||
<Configuration status="WARN" monitorInterval="30">
|
||||
|
||||
<Appenders>
|
||||
<Console name="Console" target="SYSTEM_OUT" follow="true">
|
||||
<PatternLayout pattern="[%t] [%-5level] %logger{36} - %msg%n" charset="UTF-8"/>
|
||||
</Console>
|
||||
</Appenders>
|
||||
<Loggers>
|
||||
<Logger name="org.eclipse.hawkbit.MockMvcResultPrinter" level="debug" />
|
||||
|
||||
<Root level="error">
|
||||
<AppenderRef ref="Console"/>
|
||||
</Root>
|
||||
</Loggers>
|
||||
</Configuration>
|
||||
Reference in New Issue
Block a user