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:
Kai Zimmermann
2016-01-21 13:42:38 +01:00
parent fb9dfd204c
commit 64deaeea3c
813 changed files with 9787 additions and 4929 deletions

View File

@@ -0,0 +1,37 @@
/**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.hawkbit.mgmt.api.client;
import java.util.List;
import org.eclipse.hawkbit.rest.resource.RestConstants;
import org.eclipse.hawkbit.rest.resource.model.distributionset.DistributionSetRequestBodyPost;
import org.eclipse.hawkbit.rest.resource.model.distributionset.DistributionSetsRest;
import feign.Headers;
import feign.RequestLine;
/**
* Client binding for the Distribution resource of the management API.
*/
public interface DistributionSetResource {
/**
* Creates a list of distrbution sets.
*
* @param sets
* the request body java bean containing the necessary attributes
* for creating a distribution set.
* @return the list of targets which have been created
*/
@RequestLine("POST " + RestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING)
@Headers("Content-Type: application/json")
DistributionSetsRest createDistributionSets(final List<DistributionSetRequestBodyPost> sets);
}

View File

@@ -0,0 +1,138 @@
/**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.hawkbit.mgmt.api.client;
import java.util.List;
import org.eclipse.hawkbit.rest.resource.RestConstants;
import org.eclipse.hawkbit.rest.resource.model.distributionset.DistributionSetsRest;
import org.eclipse.hawkbit.rest.resource.model.tag.AssignedDistributionSetRequestBody;
import org.eclipse.hawkbit.rest.resource.model.tag.DistributionSetTagAssigmentResultRest;
import org.eclipse.hawkbit.rest.resource.model.tag.TagRequestBodyPut;
import org.eclipse.hawkbit.rest.resource.model.tag.TagRest;
import org.eclipse.hawkbit.rest.resource.model.tag.TagsRest;
import org.eclipse.hawkbit.rest.resource.model.target.TargetsRest;
import feign.Headers;
import feign.Param;
import feign.RequestLine;
/**
* Client binding for the DistributionSetTag resource of the management API.
*/
public interface DistrubutionSetTagResource {
/**
* Retrieves a single distributionset tag based on the given ID.
*
* @param dsTagId
* the ID of the distributionset tag to retrieve
* @return a deserialized java bean containing the attributes of the
* returned distributionset tag
*/
@RequestLine("GET " + RestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING + "/{dsTagId}")
TagRest getDistributionSetTag(@Param("dsTagId") Long dsTagId);
/**
* Creates a list of distributionset tags.
*
* @param tags
* the tags to be created
* @return the created tag list
*/
@RequestLine("POST " + RestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING)
@Headers("Content-Type: application/json")
TagsRest createDistributionSetTags(List<TagRequestBodyPut> tags);
/**
* Update attributes of a distributionset tag.
*
* @param dsTagId
* the distributionset tag id to be updated
* @param tag
* the request body
* @return the updated distributionset tag
*/
@RequestLine("PUT " + RestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING + "/{dsTagId}")
@Headers("Content-Type: application/json")
TagRest updateDistributionSetTag(@Param("dsTagId") Long dsTagId, TagRequestBodyPut tag);
/**
* Deletes given distributionset tag on given ID.
*
* @param dsTagId
* to be deleted
*/
@RequestLine("DELETE " + RestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING + "/{dsTagId}")
void deleteDistributionSetTag(@Param("dsTagId") final Long dsTagId);
/**
* Retrieves a all assigned targets on the given distributionset tag id.
*
* @param dsTagId
* the ID of the distributionset tag to retrieve
* @return a list of targets
*/
@RequestLine("GET " + RestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING
+ RestConstants.DISTRIBUTIONSET_REQUEST_MAPPING)
DistributionSetsRest getAssignedDistributionSets(@Param("dsTagId") final Long dsTagId);
/**
* Toggle the tag assignment all assigned targets will be unassigned and all
* unassigned targets will be assigned.
*
* @param dsTagId
* the ID of the distributionset tag to toggle
* @param assignedTargetRequestBodies
* a list of controller ids
* @return a list of assigned and unassigned targets
*/
@RequestLine("POST " + RestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING
+ RestConstants.DISTRIBUTIONSET_REQUEST_MAPPING + "/toggleTagAssignment")
@Headers("Content-Type: application/json")
DistributionSetTagAssigmentResultRest toggleTagAssignment(@Param("dsTagId") final Long dsTagId,
final List<AssignedDistributionSetRequestBody> assignedTargetRequestBodies);
/**
* Assign targets to a given distributionset tag id.
*
* @param dsTagId
* the ID of the distributionset tag to add the targets
* @param assignedTargetRequestBodies
* a list of controller ids
* @return a list of assigned targets
*/
@RequestLine("POST " + RestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING
+ RestConstants.DISTRIBUTIONSET_REQUEST_MAPPING)
@Headers("Content-Type: application/json")
TargetsRest assignDistributionSets(@Param("dsTagId") final Long dsTagId,
final List<AssignedDistributionSetRequestBody> assignedTargetRequestBodies);
/**
* Unassign targets to a given distributionset tag id.
*
* @param dsTagId
* the ID of the distributionset tag to add the targets
*/
@RequestLine("DELETE " + RestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING
+ RestConstants.DISTRIBUTIONSET_REQUEST_MAPPING)
void unassignDistributionSets(@Param("dsTagId") final Long dsTagId);
/**
* Unassign one target to a given distributionset tag id.
*
* @param dsTagId
* the ID of the distributionset tag to add the targets param
* @param dsId
* the distributionset id
*/
@RequestLine("DELETE " + RestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING
+ RestConstants.DISTRIBUTIONSET_REQUEST_MAPPING + "/{dsId}")
void unassignDistributionSet(@Param("dsTagId") final Long dsTagId, @Param("dsId") final Long dsId);
}

View File

@@ -0,0 +1,80 @@
/**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.hawkbit.mgmt.api.client;
import java.util.List;
import org.eclipse.hawkbit.rest.resource.model.target.TargetPagedList;
import org.eclipse.hawkbit.rest.resource.model.target.TargetRequestBody;
import org.eclipse.hawkbit.rest.resource.model.target.TargetRest;
import org.eclipse.hawkbit.rest.resource.model.target.TargetsRest;
import feign.Headers;
import feign.Param;
import feign.RequestLine;
/**
* Client binding for the Target resource of the management API.
*/
public interface TargetResource {
/**
* Retrieves a single target based on the given ID.
*
* @param targetId
* the ID of the target to retrieve
* @return a deserialized java bean containing the attributes of the
* returned target
*/
@RequestLine("GET /rest/v1/targets/{targetId}")
TargetRest getTarget(@Param("targetId") final String targetId);
/**
* Paged query of targets resource.
*
* @param pagingOffsetParam
* of the paged query
* @param pagingLimitParam
* of the paged query
* @return paged list of target entries
*/
@RequestLine("GET /rest/v1/targets?offset={pagingOffsetParam}&limit={pagingLimitParam}")
TargetPagedList getTargets(@Param("pagingOffsetParam") int pagingOffsetParam,
@Param("pagingLimitParam") int pagingLimitParam);
/**
* Paged query of targets resource with default offset and limit.
*
* @return paged list of target entries
*/
@RequestLine("GET /rest/v1/targets")
TargetPagedList getTargets();
/**
* Deletes given target based on given ID.
*
* @param targetId
* to be deleted
*/
@RequestLine("DELETE /rest/v1/targets/{targetId}")
void deleteTarget(@Param("targetId") final String targetId);
/**
* Creates a list of targets.
*
* @param targets
* the request body java bean containing the necessary attributes
* for creating a target.
* @return the list of targets which have been created
*/
@RequestLine("POST /rest/v1/targets/")
@Headers("Content-Type: application/json")
TargetsRest createTargets(List<TargetRequestBody> targets);
}

View File

@@ -0,0 +1,137 @@
/**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.hawkbit.mgmt.api.client;
import java.util.List;
import org.eclipse.hawkbit.rest.resource.RestConstants;
import org.eclipse.hawkbit.rest.resource.model.tag.AssignedTargetRequestBody;
import org.eclipse.hawkbit.rest.resource.model.tag.TagRequestBodyPut;
import org.eclipse.hawkbit.rest.resource.model.tag.TagRest;
import org.eclipse.hawkbit.rest.resource.model.tag.TagsRest;
import org.eclipse.hawkbit.rest.resource.model.tag.TargetTagAssigmentResultRest;
import org.eclipse.hawkbit.rest.resource.model.target.TargetsRest;
import feign.Headers;
import feign.Param;
import feign.RequestLine;
/**
* Client binding for the Target resource of the management API.
*/
public interface TargetTagResource {
/**
* Retrieves a single target tag based on the given ID.
*
* @param targetTagId
* the ID of the target tag to retrieve
* @return a deserialized java bean containing the attributes of the
* returned target tag
*/
@RequestLine("GET " + RestConstants.TARGET_TAG_V1_REQUEST_MAPPING + "/{targetTagId}")
TagRest getTargetTag(@Param("targetTagId") Long targetTagId);
/**
* Creates a list of target tags.
*
* @param tags
* the tags to be created
* @return the created tag list
*/
@RequestLine("POST " + RestConstants.TARGET_TAG_V1_REQUEST_MAPPING)
@Headers("Content-Type: application/json")
TagsRest createTargetTag(List<TagRequestBodyPut> tags);
/**
* Update attributes of a target tag.
*
* @param targetTagId
* the target tag id to be updated
* @param tag
* the request body
* @return the updated target tag
*/
@RequestLine("PUT " + RestConstants.TARGET_TAG_V1_REQUEST_MAPPING + "/{targetTagId}")
@Headers("Content-Type: application/json")
TagRest updateTagretTag(@Param("targetTagId") Long targetTagId, TagRequestBodyPut tag);
/**
* Deletes given target tag on given ID.
*
* @param targetTagId
* to be deleted
*/
@RequestLine("DELETE " + RestConstants.TARGET_TAG_V1_REQUEST_MAPPING + "/{targetTagId}")
void deleteTargetTag(@Param("targetTagId") final Long targetTagId);
/**
* Retrieves a all assigned targets on the given target tag id.
*
* @param targetTagId
* the ID of the target tag to retrieve
* @return a list of targets
*/
@RequestLine("GET " + RestConstants.TARGET_TAG_V1_REQUEST_MAPPING
+ RestConstants.TARGET_TAG_TAGERTS_REQUEST_MAPPING)
TargetsRest getAssignedTargets(@Param("targetTagId") final Long targetTagId);
/**
* Toggle the tag assignment all assigned targets will be unassigned and all
* unassigned targets will be assigned.
*
* @param targetTagId
* the ID of the target tag to toggle
* @param assignedTargetRequestBodies
* a list of controller ids
* @return a list of assigned and unassigned targets
*/
@RequestLine("POST " + RestConstants.TARGET_TAG_V1_REQUEST_MAPPING
+ RestConstants.TARGET_TAG_TAGERTS_REQUEST_MAPPING + "/toggleTagAssignment")
@Headers("Content-Type: application/json")
TargetTagAssigmentResultRest toggleTagAssignment(@Param("targetTagId") final Long targetTagId,
final List<AssignedTargetRequestBody> assignedTargetRequestBodies);
/**
* Assign targets to a given target tag id.
*
* @param targetTagId
* the ID of the target tag to add the targets
* @param assignedTargetRequestBodies
* a list of controller ids
* @return a list of assigned targets
*/
@RequestLine("POST " + RestConstants.TARGET_TAG_V1_REQUEST_MAPPING
+ RestConstants.TARGET_TAG_TAGERTS_REQUEST_MAPPING)
@Headers("Content-Type: application/json")
TargetsRest assignTargets(@Param("targetTagId") final Long targetTagId,
final List<AssignedTargetRequestBody> assignedTargetRequestBodies);
/**
* Unassign targets to a given target tag id.
*
* @param targetTagId
* the ID of the target tag to add the targets
*/
@RequestLine("DELETE " + RestConstants.TARGET_TAG_V1_REQUEST_MAPPING
+ RestConstants.TARGET_TAG_TAGERTS_REQUEST_MAPPING)
void unassignTargets(@Param("targetTagId") final Long targetTagId);
/**
* Unassign one target to a given target tag id.
*
* @param targetTagId
* the ID of the target tag to add the targets param
* @param controllerId
* the controller id
*/
@RequestLine("DELETE " + RestConstants.TARGET_TAG_V1_REQUEST_MAPPING
+ RestConstants.TARGET_TAG_TAGERTS_REQUEST_MAPPING + "/{controllerId}")
void unassignTarget(@Param("targetTagId") final Long targetTagId, @Param("controllerId") final String controllerId);
}

View File

@@ -0,0 +1,186 @@
/**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.hawkbit.mgmt.api.client;
import static org.fest.assertions.api.Assertions.assertThat;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.hawkbit.app.Start;
import org.eclipse.hawkbit.rest.resource.model.distributionset.DistributionSetRequestBodyPost;
import org.eclipse.hawkbit.rest.resource.model.distributionset.DistributionSetRest;
import org.eclipse.hawkbit.rest.resource.model.distributionset.DistributionSetsRest;
import org.eclipse.hawkbit.rest.resource.model.tag.AssignedDistributionSetRequestBody;
import org.eclipse.hawkbit.rest.resource.model.tag.DistributionSetTagAssigmentResultRest;
import org.eclipse.hawkbit.rest.resource.model.tag.TagRequestBodyPut;
import org.eclipse.hawkbit.rest.resource.model.tag.TagRest;
import org.eclipse.hawkbit.rest.resource.model.tag.TagsRest;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.boot.SpringApplication;
import org.springframework.context.annotation.Description;
import ru.yandex.qatools.allure.annotations.Features;
import ru.yandex.qatools.allure.annotations.Stories;
import feign.Feign;
import feign.Logger;
import feign.auth.BasicAuthRequestInterceptor;
import feign.jackson.JacksonDecoder;
import feign.jackson.JacksonEncoder;
@Features("Example Tests - Management RESTful API Client")
@Stories("DistrubutionSet Tag Resource")
public class DistributionSetTagTest {
private DistrubutionSetTagResource distrubutionSetTagResource;
private static List<AssignedDistributionSetRequestBody> assignedTargetRequestBodies;
@BeforeClass
public static void startupServer() {
SpringApplication.run(Start.class, new String[0]);
createTargetsAssignment();
assignedTargetRequestBodies.add(new AssignedDistributionSetRequestBody().setDistributionSetId(100L));
}
@Before
public void setup() {
this.distrubutionSetTagResource = createDistrubutionSetTagResource();
}
// disabled as this runs not on CI environments.
@Test
@Description("Simple request of distrubutionset tag by ID")
@Ignore
public void getDistributionSetTag() {
final TagsRest result = createDistributionSetTags(2);
assertThat(distrubutionSetTagResource.getDistributionSetTag(result.get(0).getTagId()).getName()).isEqualTo(
"Tag0");
deleteDistributionSets(result);
}
// disabled as this runs not on CI environments.
@Test
@Description("Simple update of a distrubutionset tag")
@Ignore
public void updateDistributionSetTag() {
final TagsRest created = createDistributionSetTags(10);
distrubutionSetTagResource.updateDistributionSetTag(created.get(0).getTagId(), new TagRequestBodyPut()
.setDescription("Test").setName("Test").setColour("Green"));
final TagRest targetTag = distrubutionSetTagResource.getDistributionSetTag(created.get(0).getTagId());
assertThat(targetTag.getName()).isEqualTo("Test");
assertThat(targetTag.getDescription()).isEqualTo("Test");
assertThat(targetTag.getColour()).isEqualTo("Green");
deleteDistributionSets(created);
}
// disabled as this runs not on CI environments.
@Test
@Description("Simple request of all assigned distrubutionsets by a distrubutionset tag.")
@Ignore
public void getDistributionSetByTagId() {
final TagsRest created = createDistributionSetTags(10);
distrubutionSetTagResource.assignDistributionSets(created.get(2).getTagId(), assignedTargetRequestBodies);
final DistributionSetsRest distributionSetsRest = distrubutionSetTagResource
.getAssignedDistributionSets(created.get(2).getTagId());
assertThat(distributionSetsRest).hasSize(5);
distrubutionSetTagResource.unassignDistributionSets(created.get(2).getTagId());
deleteDistributionSets(created);
}
@Test
@Description("Toggle request to unassigned all assigned distrubutionset and assign all unassigned distrubutionset.")
@Ignore
public void toggleTagAssignment() {
final TagsRest created = createDistributionSetTags(10);
final Long id = created.get(2).getTagId();
distrubutionSetTagResource.assignDistributionSets(id, assignedTargetRequestBodies);
distrubutionSetTagResource.unassignDistributionSet(id, assignedTargetRequestBodies.get(0)
.getDistributionSetId());
DistributionSetTagAssigmentResultRest assigmentResultRest = distrubutionSetTagResource.toggleTagAssignment(id,
assignedTargetRequestBodies);
final TagRest targetTag = distrubutionSetTagResource.getDistributionSetTag(created.get(2).getTagId());
assertThat(assigmentResultRest.getAssignedDistributionSets()).hasSize(1);
assertThat(assigmentResultRest.getUnassignedDistributionSets()).hasSize(0);
assigmentResultRest = distrubutionSetTagResource.toggleTagAssignment(id, assignedTargetRequestBodies);
assertThat(assigmentResultRest.getAssignedDistributionSets()).hasSize(0);
assertThat(assigmentResultRest.getUnassignedDistributionSets()).hasSize(5);
distrubutionSetTagResource.unassignDistributionSets(targetTag.getTagId());
deleteDistributionSets(created);
}
private void deleteDistributionSets(final List<TagRest> tags) {
for (final TagRest tag : tags) {
distrubutionSetTagResource.deleteDistributionSetTag(tag.getTagId());
}
}
private TagsRest createDistributionSetTags(final int number) {
final List<TagRequestBodyPut> tags = new ArrayList<>();
for (int i = 0; i < number; i++) {
tags.add(new TagRequestBodyPut().setDescription("Tag " + i).setName("Tag" + i).setColour("Red"));
}
final TagsRest result = distrubutionSetTagResource.createDistributionSetTags(tags);
assertThat(result).hasSize(number);
return result;
}
private DistrubutionSetTagResource createDistrubutionSetTagResource() {
final DistrubutionSetTagResource distrubutionSetTagResource = Feign.builder().logger(new Logger.ErrorLogger())
.logLevel(Logger.Level.BASIC).decoder(new JacksonDecoder()).encoder(new JacksonEncoder())
.requestInterceptor(new BasicAuthRequestInterceptor("admin", "admin"))
.target(DistrubutionSetTagResource.class, "http://localhost:8080");
return distrubutionSetTagResource;
}
private static void createTargetsAssignment() {
final List<DistributionSetRequestBodyPost> sets = new ArrayList<>();
assignedTargetRequestBodies = new ArrayList<>();
for (int i = 0; i < 5; i++) {
final DistributionSetRequestBodyPost bodyPost = (DistributionSetRequestBodyPost) new DistributionSetRequestBodyPost()
.setName("Ds" + i).setDescription("Ds" + i).setVersion("" + i);
sets.add(bodyPost);
}
final DistributionSetsRest result = createDistributionSetResource().createDistributionSets(sets);
for (final DistributionSetRest rest : result) {
assignedTargetRequestBodies.add(new AssignedDistributionSetRequestBody().setDistributionSetId(rest
.getDsId()));
}
}
private static DistributionSetResource createDistributionSetResource() {
final DistributionSetResource distributionSetResource = Feign.builder().logger(new Logger.ErrorLogger())
.logLevel(Logger.Level.BASIC).decoder(new JacksonDecoder()).encoder(new JacksonEncoder())
.requestInterceptor(new BasicAuthRequestInterceptor("admin", "admin"))
.target(DistributionSetResource.class, "http://localhost:8080");
return distributionSetResource;
}
}

View File

@@ -0,0 +1,182 @@
/**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.hawkbit.mgmt.api.client;
import static org.fest.assertions.api.Assertions.assertThat;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.hawkbit.app.Start;
import org.eclipse.hawkbit.rest.resource.model.tag.AssignedTargetRequestBody;
import org.eclipse.hawkbit.rest.resource.model.tag.TagRequestBodyPut;
import org.eclipse.hawkbit.rest.resource.model.tag.TagRest;
import org.eclipse.hawkbit.rest.resource.model.tag.TagsRest;
import org.eclipse.hawkbit.rest.resource.model.tag.TargetTagAssigmentResultRest;
import org.eclipse.hawkbit.rest.resource.model.target.TargetRequestBody;
import org.eclipse.hawkbit.rest.resource.model.target.TargetRest;
import org.eclipse.hawkbit.rest.resource.model.target.TargetsRest;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.boot.SpringApplication;
import org.springframework.context.annotation.Description;
import ru.yandex.qatools.allure.annotations.Features;
import ru.yandex.qatools.allure.annotations.Stories;
import feign.Feign;
import feign.Logger;
import feign.auth.BasicAuthRequestInterceptor;
import feign.jackson.JacksonDecoder;
import feign.jackson.JacksonEncoder;
@Features("Example Tests - Management RESTful API Client")
@Stories("Target Tag Resource")
public class TargetTagTest {
private TargetTagResource targetTagResource;
private static List<AssignedTargetRequestBody> assignedTargetRequestBodies;
@BeforeClass
public static void startupServer() {
SpringApplication.run(Start.class, new String[0]);
createTargetsAssignment();
assignedTargetRequestBodies.add(new AssignedTargetRequestBody().setControllerId("NotExist"));
}
@Before
public void setup() {
this.targetTagResource = createTargetTagResource();
}
// disabled as this runs not on CI environments.
@Test
@Description("Simple request of target tag by ID")
@Ignore
public void getTargetTag() {
final TagsRest result = createTargetTags(2);
assertThat(targetTagResource.getTargetTag(result.get(0).getTagId()).getName()).isEqualTo("Tag0");
deleteTargets(result);
}
// disabled as this runs not on CI environments.
@Test
@Description("Simple update of a target tag")
@Ignore
public void updateTargetTag() {
final TagsRest created = createTargetTags(10);
targetTagResource.updateTagretTag(created.get(0).getTagId(), new TagRequestBodyPut().setDescription("Test")
.setName("Test").setColour("Green"));
final TagRest targetTag = targetTagResource.getTargetTag(created.get(0).getTagId());
assertThat(targetTag.getName()).isEqualTo("Test");
assertThat(targetTag.getDescription()).isEqualTo("Test");
assertThat(targetTag.getColour()).isEqualTo("Green");
deleteTargets(created);
}
// disabled as this runs not on CI environments.
@Test
@Description("Simple request of all assigned targets by a target tag.")
@Ignore
public void getTargetsByTargetTagId() {
final TagsRest created = createTargetTags(10);
final Long tagId = created.get(2).getTagId();
targetTagResource.assignTargets(tagId, assignedTargetRequestBodies);
final TagRest targetTag = targetTagResource.getTargetTag(tagId);
assertThat(targetTagResource.getAssignedTargets(tagId)).hasSize(5);
targetTagResource.unassignTargets(targetTag.getTagId());
deleteTargets(created);
}
@Test
@Description("Toggle request to unassigned all assigned targets and assign all unassigned targets.")
@Ignore
public void toggleTagAssignment() {
final TagsRest created = createTargetTags(10);
final Long id = created.get(2).getTagId();
targetTagResource.assignTargets(id, assignedTargetRequestBodies);
targetTagResource.unassignTarget(id, assignedTargetRequestBodies.get(0).getControllerId());
TargetTagAssigmentResultRest assigmentResultRest = targetTagResource.toggleTagAssignment(id,
assignedTargetRequestBodies);
final TagRest targetTag = targetTagResource.getTargetTag(created.get(2).getTagId());
assertThat(assigmentResultRest.getAssignedTargets()).hasSize(1);
assertThat(assigmentResultRest.getUnassignedTargets()).hasSize(0);
assigmentResultRest = targetTagResource.toggleTagAssignment(id, assignedTargetRequestBodies);
assertThat(assigmentResultRest.getAssignedTargets()).hasSize(0);
assertThat(assigmentResultRest.getUnassignedTargets()).hasSize(5);
targetTagResource.unassignTargets(targetTag.getTagId());
deleteTargets(created);
}
private void deleteTargets(final List<TagRest> tags) {
for (final TagRest tag : tags) {
targetTagResource.deleteTargetTag(tag.getTagId());
}
}
private TagsRest createTargetTags(final int number) {
final List<TagRequestBodyPut> tags = new ArrayList<>();
for (int i = 0; i < number; i++) {
tags.add(new TagRequestBodyPut().setDescription("Tag " + i).setName("Tag" + i).setColour("Red"));
}
final TagsRest result = targetTagResource.createTargetTag(tags);
assertThat(result).hasSize(number);
return result;
}
private TargetTagResource createTargetTagResource() {
final TargetTagResource targetResource = Feign.builder().logger(new Logger.ErrorLogger())
.logLevel(Logger.Level.BASIC).decoder(new JacksonDecoder()).encoder(new JacksonEncoder())
.requestInterceptor(new BasicAuthRequestInterceptor("admin", "admin"))
.target(TargetTagResource.class, "http://localhost:8080");
return targetResource;
}
private static void createTargetsAssignment() {
final List<TargetRequestBody> targets = new ArrayList<>();
assignedTargetRequestBodies = new ArrayList<>();
for (int i = 0; i < 5; i++) {
targets.add(new TargetRequestBody().setControllerId("test" + i).setName("testDevice"));
}
final TargetsRest result = createTargetResource().createTargets(targets);
for (final TargetRest rest : result) {
assignedTargetRequestBodies.add(new AssignedTargetRequestBody().setControllerId(rest.getControllerId()));
}
}
private static TargetResource createTargetResource() {
final TargetResource targetResource = Feign.builder().logger(new Logger.ErrorLogger())
.logLevel(Logger.Level.BASIC).decoder(new JacksonDecoder()).encoder(new JacksonEncoder())
.requestInterceptor(new BasicAuthRequestInterceptor("admin", "admin"))
.target(TargetResource.class, "http://localhost:8080");
return targetResource;
}
}

View File

@@ -0,0 +1,119 @@
/**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.hawkbit.mgmt.api.client;
import static org.fest.assertions.api.Assertions.assertThat;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.hawkbit.app.Start;
import org.eclipse.hawkbit.rest.resource.model.target.TargetPagedList;
import org.eclipse.hawkbit.rest.resource.model.target.TargetRequestBody;
import org.eclipse.hawkbit.rest.resource.model.target.TargetRest;
import org.eclipse.hawkbit.rest.resource.model.target.TargetsRest;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.boot.SpringApplication;
import org.springframework.context.annotation.Description;
import feign.Feign;
import feign.Logger;
import feign.auth.BasicAuthRequestInterceptor;
import feign.jackson.JacksonDecoder;
import feign.jackson.JacksonEncoder;
import ru.yandex.qatools.allure.annotations.Features;
import ru.yandex.qatools.allure.annotations.Stories;
@Features("Example Tests - Management RESTful API Client")
@Stories("Target Resource")
public class TargetTest {
@BeforeClass
public static void startupServer() {
SpringApplication.run(Start.class, new String[0]);
}
// disabled as this runs not on CI environments.
@Test
@Description("Simple request of target by ID")
@Ignore
public void getTarget() {
final TargetResource targetResource = createTargetResource();
final TargetsRest result = createTargets(targetResource, 1);
assertThat(targetResource.getTarget("test0").getName()).isEqualTo("testDevice");
deleteTargets(targetResource, result);
}
// disabled as this runs not on CI environments.
@Test
@Description("Simple request of all targets with defined page sizing information (i.e. offset and limit).")
@Ignore
public void getTargetsAsPagedListWithDefinedPageSizing() {
final TargetResource targetResource = createTargetResource();
final TargetsRest created = createTargets(targetResource, 20);
final TargetPagedList queryResult = targetResource.getTargets(0, 10);
assertThat(queryResult.getContent()).hasSize(10);
assertThat(queryResult.getTotal()).isEqualTo(20);
assertThat(queryResult.getSize()).isEqualTo(10);
deleteTargets(targetResource, created);
}
// disabled as this runs not on CI environments.
@Test
@Description("Simple request of all targets with defualt paging parameters.")
@Ignore
public void getTargetsAsPagedListWithDefaultPageSizing() {
final TargetResource targetResource = createTargetResource();
final TargetsRest created = createTargets(targetResource, 20);
final TargetPagedList queryResult = targetResource.getTargets();
assertThat(queryResult.getContent()).hasSize(20);
assertThat(queryResult.getTotal()).isEqualTo(20);
assertThat(queryResult.getSize()).isEqualTo(20);
deleteTargets(targetResource, created);
}
private void deleteTargets(final TargetResource targetResource, final List<TargetRest> targets) {
for (final TargetRest targetRest : targets) {
targetResource.deleteTarget(targetRest.getControllerId());
}
}
private TargetsRest createTargets(final TargetResource targetResource, final int number) {
final List<TargetRequestBody> targets = new ArrayList<>();
for (int i = 0; i < number; i++) {
targets.add(new TargetRequestBody().setControllerId("test" + i).setName("testDevice"));
}
final TargetsRest result = targetResource.createTargets(targets);
assertThat(result).hasSize(number);
return result;
}
private TargetResource createTargetResource() {
final TargetResource targetResource = Feign.builder().logger(new Logger.ErrorLogger())
.logLevel(Logger.Level.BASIC).decoder(new JacksonDecoder()).encoder(new JacksonEncoder())
.requestInterceptor(new BasicAuthRequestInterceptor("admin", "admin"))
.target(TargetResource.class, "http://localhost:8080");
return targetResource;
}
}