summaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-sdc-externaltesting-lib/openecomp-sdc-externaltesting-api/src/test/java/org/openecomp/core/externaltesting/api/ExecutionRequestTests.java
blob: b10d3079d20b50b59bd7a8fe92fa837a8367ca4e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
 * Copyright © 2019 iconectiv
 *
 * Licensed 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.openecomp.core.externaltesting.api;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Assert;
import org.junit.Test;

import java.io.File;
import java.io.IOException;
import java.util.Map;
import java.util.UUID;

public class ExecutionRequestTests {

  @Test
  public void testTestCase() throws Exception {
    ObjectMapper mapper = new ObjectMapper();
    VtpTestCase req = mapper.readValue(new File("src/test/data/testcase.json"), VtpTestCase.class);

    Assert.assertEquals("Scenario must match", "compliance", req.getScenario());
    Assert.assertEquals("Suite name must match", "compliancetests", req.getTestSuiteName());
    Assert.assertEquals("Test case name must match", "sriov", req.getTestCaseName());
    Assert.assertEquals("Description must match", "SR-IOV Test", req.getDescription());
    Assert.assertEquals("Author must match", "Jim", req.getAuthor());
    Assert.assertEquals("Endpoint must match", "vtp", req.getEndpoint());
    Assert.assertEquals("Test must contain two inputs", 3, req.getInputs().size());
    Assert.assertEquals("Test must contain one outputs", 1, req.getOutputs().size());

    VtpTestCaseInput input1 = req.getInputs().get(0);
    Assert.assertEquals("Name match", "vspId", input1.getName());
    Assert.assertEquals("Description match", "VSP ID", input1.getDescription());
    Assert.assertEquals("Input type match", "text", input1.getType());
    Assert.assertEquals("Input default match", "", input1.getDefaultValue());
    Assert.assertFalse("Input optional match", input1.getIsOptional());

    VtpTestCaseOutput output1 = req.getOutputs().get(0);
    Assert.assertEquals("Name match", "something", output1.getName());
    Assert.assertEquals("Description match", "is produced", output1.getDescription());
    Assert.assertEquals("Output type match", "integer", output1.getType());


    Map<String,Object> meta = input1.getMetadata();
    Assert.assertEquals("Metadata count", 3, meta.size());

    VtpTestCase req2 = mapper.readValue(new File("src/test/data/testcase.json"), VtpTestCase.class);

    Assert.assertEquals("test equality", req, req2);

  }

  @Test
  public void testExecutionRequest() throws IOException {
    ObjectMapper mapper = new ObjectMapper();
    VtpTestExecutionRequest req = mapper.readValue(new File("src/test/data/executionrequest.json"), VtpTestExecutionRequest.class);
    Assert.assertEquals("compliance", req.getScenario());
    Assert.assertEquals("compliance", req.getProfile());
    Assert.assertEquals("sriov", req.getTestCaseName());
    Assert.assertEquals("compliancetests", req.getTestSuiteName());
    Assert.assertEquals("repository", req.getEndpoint());

    Assert.assertEquals(3, req.getParameters().size());
  }

  @Test
  public void testExecutionResponse() throws IOException {
    ObjectMapper mapper = new ObjectMapper();
    VtpTestExecutionResponse rsp = mapper.readValue(new File("src/test/data/priorexecution.json"), VtpTestExecutionResponse.class);
    Assert.assertEquals("compliance", rsp.getScenario());
    Assert.assertEquals("computeflavors", rsp.getTestCaseName());
    Assert.assertEquals("compliancetests", rsp.getTestSuiteName());
    Assert.assertTrue(UUID.fromString(rsp.getExecutionId()).getLeastSignificantBits() != 0);
    Assert.assertEquals("parameters", 6, rsp.getParameters().size());
    Assert.assertNotNull(rsp.getResults());
    Assert.assertEquals("COMPLETED", rsp.getStatus());
    Assert.assertNotNull(rsp.getStartTime());
    Assert.assertNotNull(rsp.getEndTime());
  }

  @Test
  public void testTree() throws IOException {
    ObjectMapper mapper = new ObjectMapper();
    TestTreeNode tree = mapper.readValue(new File("src/test/data/testtree.json"), TestTreeNode.class);

    Assert.assertEquals(2, tree.getChildren().size());
    Assert.assertEquals(0, tree.getTests().size());

    TestTreeNode manual = new TestTreeNode("root", "Root");

    manual.addChild(new TestTreeNode("child", "child"));
    manual.addTest(new VtpTestCase());
    Assert.assertEquals(1, manual.getChildren().size());
    Assert.assertEquals(1, manual.getTests().size());

  }
}