8f252c31e6aecf982a19781930a732e30003fab0
[oom/platform/cert-service.git] / certServiceClient / src / test / java / org / onap / aaf / certservice / client / CerServiceRequestTestData.java
1 /*
2  * ============LICENSE_START=======================================================
3  * aaf-certservice-client
4  * ================================================================================
5  * Copyright (C) 2020 Nokia. 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.aaf.certservice.client;
22
23 import java.io.IOException;
24 import java.nio.charset.StandardCharsets;
25 import java.nio.file.Files;
26 import java.nio.file.Paths;
27
28 public final class CerServiceRequestTestData {
29
30     private static final String RESOURCE_PATH = "src/test/resources/";
31
32     // Request parameters
33     public static final String CA_NAME = "TestCA";
34     public static final String CSR = getCsrValue();
35     public static final String PK = getPkValue();
36
37     // Correct response data
38     public static final String CORRECT_RESPONSE = getCorrectResponse();
39     public static final String EXPECTED_FIRST_ELEMENT_OF_CERTIFICATE_CHAIN =
40             getExpectedFirstElementOfCertificateChain();
41     public static final String EXPECTED_FIRST_ELEMENT_OF_TRUSTED_CERTIFICATES =
42             getExpectedFirstElementOfTrustedCertificates();
43
44     // Error response data
45     public static final String MISSING_PK_RESPONSE = getMissingPkResponse();
46
47     private CerServiceRequestTestData() {
48     }
49
50     private static String getMissingPkResponse() {
51         String fileName = "missingPkResponse";
52         return readFromFile(RESOURCE_PATH + fileName);
53     }
54
55     private static String getExpectedFirstElementOfTrustedCertificates() {
56
57         String fileName = "expectedFirstElementOfTrustedCertificates";
58         return readFromFile(RESOURCE_PATH + fileName);
59     }
60
61     private static String getExpectedFirstElementOfCertificateChain() {
62         String fileName = "expectedFirstElementOfCertificateChain";
63         return readFromFile(RESOURCE_PATH + fileName);
64     }
65
66     private static String getCorrectResponse() {
67         String fileName = "correctResponse";
68         return readFromFile(RESOURCE_PATH + fileName);
69     }
70
71     private static String getPkValue() {
72         String fileName = "testPk";
73         return readFromFile(RESOURCE_PATH + fileName);
74     }
75
76     private static String getCsrValue() {
77         String fileName = "testCsr";
78         return readFromFile(RESOURCE_PATH + fileName);
79     }
80
81     private static String readFromFile(String path) {
82         try {
83             return Files.readString(Paths.get(path), StandardCharsets.UTF_8);
84         } catch (IOException e) {
85             e.printStackTrace();
86             return "File not found";
87         }
88     }
89 }