2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.sdc.gab.cucumber.actions.gabcontroller;
23 import static org.junit.Assert.assertEquals;
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;
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;
38 public class GABControllerStepDefinitions {
40 private GABService gabService;
42 private GABQueryType gabQueryType;
43 private Set<String> headers;
44 private GABResults actualAnswer;
46 public GABControllerStepDefinitions() {
47 headers = new HashSet<>();
51 public void createNewGABService() {
52 gabService = new GABServiceImpl();
55 @Given("^yaml document \"([^\"]*)\" of type \"([^\"]*)\"$")
56 public void prepareYamlFile(String yaml, String type) {
58 this.gabQueryType = GABQueryType.valueOf(type);
61 @Given("^header to search \"([^\"]*)\"$")
62 public void prepareHeader(String header) {
63 this.headers.add(header);
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);
72 @Then("^Service should find (\\d+) results$")
73 public void checkSizeOfTheAnswerEquals(int size) {
74 assertEquals(actualAnswer.getRows().size(), size);