CLOUDSTACK-9957 test fix (#2297)

* tyopos in test
* unittest to prove interface
* test logic flaw fixed
This commit is contained in:
dahn 2017-10-19 08:57:47 +02:00 committed by GitHub
parent 4c89b5b97a
commit 285fd77674
3 changed files with 51 additions and 5 deletions

View File

@ -49,10 +49,16 @@ public class AddAnnotationCmd extends BaseCmd {
return annotation;
}
protected void setEntityType(String newType) {
entityType = newType;
}
public AnnotationService.EntityType getEntityType() {
return AnnotationService.EntityType.valueOf(entityType);
}
protected void setEntityUuid(String newUuid) {
entityUuid = newUuid;
}
public String getEntityUuid() {
return entityUuid;
}
@ -61,7 +67,7 @@ public class AddAnnotationCmd extends BaseCmd {
public void execute()
throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException,
NetworkRuleConflictException {
Preconditions.checkNotNull(entityUuid,"I have to have an entity to set an annotation on!");
Preconditions.checkNotNull(getEntityUuid(),"I have to have an entity to set an annotation on!");
Preconditions.checkState(AnnotationService.EntityType.contains(entityType),(java.lang.String)"'%s' is ot a valid EntityType to put annotations on", entityType);
AnnotationResponse annotationResponse = annotationService.addAnnotation(this);
annotationResponse.setResponseName(getCommandName());

View File

@ -0,0 +1,40 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.cloudstack.api.command.admin.annotation;
import org.junit.Before;
import org.junit.Test;
import org.mockito.MockitoAnnotations;
public class AddAnnotationCmdTest {
private AddAnnotationCmd addAnnotationCmd = new AddAnnotationCmd();
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
}
@Test (expected = IllegalStateException.class)
public void wrongEntityType() throws Exception {
addAnnotationCmd.setEntityType("BLA");
addAnnotationCmd.setEntityUuid("1");
addAnnotationCmd.execute();
}
}

View File

@ -162,16 +162,16 @@ class TestHostAnnotations(cloudstackTestCase):
@attr(tags=["devcloud", "advanced", "advancedns", "smoke", "basic", "sg"], required_hardware="false")
def test_05_add_annotation_for_invvalid_entityType(self):
def test_05_add_annotation_for_invalid_entityType(self):
cmd = addAnnotation.addAnnotationCmd()
cmd.entityid = self.host.id
cmd.entitytype = "BLA"
cmd.annotation = annotation
cmd.annotation = "annotation"
try:
self.apiclient.addAnnotation(cmd)
except CloudstackAPIException as f:
log.debug("error message %s" % f)
except Exception as f:
pass
else:
self.fail("AddAnnotation is allowed for on an unknown entityType")