Introduced yaml parser as common lib
[sdc.git] / common / onap-generic-artifact-browser / onap-generic-artifact-browser-component-tests / src / test / java / org / onap / sdc / gab / cucumber / actions / gabcontroller / GABControllerStepDefinitions.java
1 /*
2  * ============LICENSE_START=======================================================
3  * GAB
4  * ================================================================================
5  * Copyright (C) 2019 Nokia Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.sdc.gab.cucumber.actions.gabcontroller;
22
23 import static org.junit.Assert.assertEquals;
24
25 import cucumber.api.java.Before;
26 import cucumber.api.java.en.Given;
27 import cucumber.api.java.en.When;
28 import cucumber.api.java.en.Then;
29 import java.io.IOException;
30 import java.util.HashSet;
31 import java.util.Set;
32 import org.onap.sdc.gab.GABService;
33 import org.onap.sdc.gab.GABServiceImpl;
34 import org.onap.sdc.gab.model.GABQuery;
35 import org.onap.sdc.gab.model.GABQuery.GABQueryType;
36 import org.onap.sdc.gab.model.GABResults;
37
38 public class GABControllerStepDefinitions {
39
40     private GABService gabService;
41     private String yaml;
42     private GABQueryType gabQueryType;
43     private Set<String> headers;
44     private GABResults actualAnswer;
45
46     public GABControllerStepDefinitions() {
47         headers = new HashSet<>();
48     }
49
50     @Before
51     public void createNewGABService() {
52         gabService = new GABServiceImpl();
53     }
54
55     @Given("^yaml document \"([^\"]*)\" of type \"([^\"]*)\"$")
56     public void prepareYamlFile(String yaml, String type) {
57         this.yaml = yaml;
58         this.gabQueryType = GABQueryType.valueOf(type);
59     }
60
61     @Given("^header to search \"([^\"]*)\"$")
62     public void prepareHeader(String header) {
63         this.headers.add(header);
64     }
65
66     @When("^I ask service for results$")
67     public void executeSearchQuery() throws IOException {
68         GABQuery gabQuery = new GABQuery(headers, yaml, gabQueryType);
69         actualAnswer = gabService.searchFor(gabQuery);
70     }
71
72     @Then("^Service should find (\\d+) results$")
73     public void checkSizeOfTheAnswerEquals(int size) {
74         assertEquals(actualAnswer.getRows().size(), size);
75     }
76
77 }