diff options
Diffstat (limited to 'main/src/main/java/org/onap/policy/pap/main/rest/stub')
12 files changed, 755 insertions, 0 deletions
diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/stub/HealthCheckRestControllerV1Stub.java b/main/src/main/java/org/onap/policy/pap/main/rest/stub/HealthCheckRestControllerV1Stub.java new file mode 100644 index 00000000..08bc645e --- /dev/null +++ b/main/src/main/java/org/onap/policy/pap/main/rest/stub/HealthCheckRestControllerV1Stub.java @@ -0,0 +1,44 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2023 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.pap.main.rest.stub; + +import lombok.RequiredArgsConstructor; +import org.onap.policy.common.endpoints.report.HealthCheckReport; +import org.onap.policy.pap.main.rest.HealthCheckRestControllerV1Api; +import org.onap.policy.pap.main.rest.PapRestControllerV1; +import org.springframework.context.annotation.Profile; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequiredArgsConstructor +@Profile("stub") +public class HealthCheckRestControllerV1Stub extends PapRestControllerV1 + implements HealthCheckRestControllerV1Api { + + private final StubUtils stubUtils; + + @Override + public ResponseEntity<HealthCheckReport> healthcheck() { + return stubUtils.getStubbedResponse(HealthCheckReport.class); + } + +} diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/stub/PdpGroupCreateOrUpdateControllerV1Stub.java b/main/src/main/java/org/onap/policy/pap/main/rest/stub/PdpGroupCreateOrUpdateControllerV1Stub.java new file mode 100644 index 00000000..81ab6366 --- /dev/null +++ b/main/src/main/java/org/onap/policy/pap/main/rest/stub/PdpGroupCreateOrUpdateControllerV1Stub.java @@ -0,0 +1,48 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2023 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.pap.main.rest.stub; + +import java.util.UUID; +import javax.validation.Valid; +import lombok.RequiredArgsConstructor; +import org.onap.policy.models.pap.concepts.PdpGroupUpdateResponse; +import org.onap.policy.models.pdp.concepts.PdpGroups; +import org.onap.policy.pap.main.rest.PapRestControllerV1; +import org.onap.policy.pap.main.rest.PdpGroupCreateOrUpdateControllerV1Api; +import org.springframework.context.annotation.Profile; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequiredArgsConstructor +@Profile("stub") +public class PdpGroupCreateOrUpdateControllerV1Stub extends PapRestControllerV1 + implements PdpGroupCreateOrUpdateControllerV1Api { + + private final StubUtils stubUtils; + + @Override + public ResponseEntity<PdpGroupUpdateResponse> createOrUpdateGroups( + UUID requestId, @Valid PdpGroups body) { + return stubUtils.getStubbedResponse(PdpGroupUpdateResponse.class); + } + +} diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/stub/PdpGroupDeleteControllerV1Stub.java b/main/src/main/java/org/onap/policy/pap/main/rest/stub/PdpGroupDeleteControllerV1Stub.java new file mode 100644 index 00000000..9f464300 --- /dev/null +++ b/main/src/main/java/org/onap/policy/pap/main/rest/stub/PdpGroupDeleteControllerV1Stub.java @@ -0,0 +1,59 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2023 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.pap.main.rest.stub; + +import java.util.UUID; +import lombok.RequiredArgsConstructor; +import org.onap.policy.models.pap.concepts.PdpGroupDeleteResponse; +import org.onap.policy.models.pap.concepts.PdpGroupDeployResponse; +import org.onap.policy.pap.main.rest.PapRestControllerV1; +import org.onap.policy.pap.main.rest.PdpGroupDeleteControllerV1Api; +import org.springframework.context.annotation.Profile; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequiredArgsConstructor +@Profile("stub") +public class PdpGroupDeleteControllerV1Stub extends PapRestControllerV1 + implements PdpGroupDeleteControllerV1Api { + + private final StubUtils stubUtils; + + @Override + public ResponseEntity<PdpGroupDeleteResponse> deleteGroup( + String name, UUID requestId) { + return stubUtils.getStubbedResponse(PdpGroupDeleteResponse.class); + } + + @Override + public ResponseEntity<PdpGroupDeployResponse> deletePolicy( + String name, UUID requestId) { + return stubUtils.getStubbedResponse(PdpGroupDeployResponse.class); + } + + @Override + public ResponseEntity<PdpGroupDeployResponse> deletePolicyVersion( + String name, String version, UUID requestId) { + return stubUtils.getStubbedResponse(PdpGroupDeployResponse.class); + } + +} diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/stub/PdpGroupDeployControllerV1Stub.java b/main/src/main/java/org/onap/policy/pap/main/rest/stub/PdpGroupDeployControllerV1Stub.java new file mode 100644 index 00000000..f9ed98e4 --- /dev/null +++ b/main/src/main/java/org/onap/policy/pap/main/rest/stub/PdpGroupDeployControllerV1Stub.java @@ -0,0 +1,55 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2023 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.pap.main.rest.stub; + +import java.util.UUID; +import javax.validation.Valid; +import lombok.RequiredArgsConstructor; +import org.onap.policy.models.pap.concepts.PdpDeployPolicies; +import org.onap.policy.models.pap.concepts.PdpGroupDeployResponse; +import org.onap.policy.models.pdp.concepts.DeploymentGroups; +import org.onap.policy.pap.main.rest.PapRestControllerV1; +import org.onap.policy.pap.main.rest.PdpGroupDeployControllerV1Api; +import org.springframework.context.annotation.Profile; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequiredArgsConstructor +@Profile("stub") +public class PdpGroupDeployControllerV1Stub extends PapRestControllerV1 + implements PdpGroupDeployControllerV1Api { + + private final StubUtils stubUtils; + + @Override + public ResponseEntity<PdpGroupDeployResponse> deployPolicies( + UUID requestId, @Valid PdpDeployPolicies body) { + return stubUtils.getStubbedResponse(PdpGroupDeployResponse.class); + } + + @Override + public ResponseEntity<PdpGroupDeployResponse> updateGroupPolicies( + UUID requestId, @Valid DeploymentGroups body) { + return stubUtils.getStubbedResponse(PdpGroupDeployResponse.class); + } + +} diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/stub/PdpGroupHealthCheckControllerV1Stub.java b/main/src/main/java/org/onap/policy/pap/main/rest/stub/PdpGroupHealthCheckControllerV1Stub.java new file mode 100644 index 00000000..a65f02bc --- /dev/null +++ b/main/src/main/java/org/onap/policy/pap/main/rest/stub/PdpGroupHealthCheckControllerV1Stub.java @@ -0,0 +1,45 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2023 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.pap.main.rest.stub; + +import java.util.UUID; +import lombok.RequiredArgsConstructor; +import org.onap.policy.models.pdp.concepts.Pdps; +import org.onap.policy.pap.main.rest.PapRestControllerV1; +import org.onap.policy.pap.main.rest.PdpGroupHealthCheckControllerV1Api; +import org.springframework.context.annotation.Profile; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequiredArgsConstructor +@Profile("stub") +public class PdpGroupHealthCheckControllerV1Stub extends PapRestControllerV1 + implements PdpGroupHealthCheckControllerV1Api { + + private final StubUtils stubUtils; + + @Override + public ResponseEntity<Pdps> pdpGroupHealthCheck(UUID requestId) { + return stubUtils.getStubbedResponse(Pdps.class); + } + +} diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/stub/PdpGroupQueryControllerV1Stub.java b/main/src/main/java/org/onap/policy/pap/main/rest/stub/PdpGroupQueryControllerV1Stub.java new file mode 100644 index 00000000..12e44ac3 --- /dev/null +++ b/main/src/main/java/org/onap/policy/pap/main/rest/stub/PdpGroupQueryControllerV1Stub.java @@ -0,0 +1,45 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2023 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.pap.main.rest.stub; + +import java.util.UUID; +import lombok.RequiredArgsConstructor; +import org.onap.policy.models.pdp.concepts.PdpGroups; +import org.onap.policy.pap.main.rest.PapRestControllerV1; +import org.onap.policy.pap.main.rest.PdpGroupQueryControllerV1Api; +import org.springframework.context.annotation.Profile; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequiredArgsConstructor +@Profile("stub") +public class PdpGroupQueryControllerV1Stub extends PapRestControllerV1 + implements PdpGroupQueryControllerV1Api { + + private final StubUtils stubUtils; + + @Override + public ResponseEntity<PdpGroups> queryGroupDetails(UUID requestId) { + return stubUtils.getStubbedResponse(PdpGroups.class); + } + +} diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/stub/PdpGroupStateChangeControllerV1Stub.java b/main/src/main/java/org/onap/policy/pap/main/rest/stub/PdpGroupStateChangeControllerV1Stub.java new file mode 100644 index 00000000..dc4f236f --- /dev/null +++ b/main/src/main/java/org/onap/policy/pap/main/rest/stub/PdpGroupStateChangeControllerV1Stub.java @@ -0,0 +1,49 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2023 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.pap.main.rest.stub; + +import java.util.UUID; +import javax.validation.Valid; +import javax.validation.constraints.NotNull; +import lombok.RequiredArgsConstructor; +import org.onap.policy.models.pap.concepts.PdpGroupStateChangeResponse; +import org.onap.policy.models.pdp.enums.PdpState; +import org.onap.policy.pap.main.rest.PapRestControllerV1; +import org.onap.policy.pap.main.rest.PdpGroupStateChangeControllerV1Api; +import org.springframework.context.annotation.Profile; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequiredArgsConstructor +@Profile("stub") +public class PdpGroupStateChangeControllerV1Stub extends PapRestControllerV1 + implements PdpGroupStateChangeControllerV1Api { + + private final StubUtils stubUtils; + + @Override + public ResponseEntity<PdpGroupStateChangeResponse> changeGroupState( + String name, @NotNull @Valid PdpState state, UUID requestId) { + return stubUtils.getStubbedResponse(PdpGroupStateChangeResponse.class); + } + +} diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/stub/PolicyAuditControllerV1Stub.java b/main/src/main/java/org/onap/policy/pap/main/rest/stub/PolicyAuditControllerV1Stub.java new file mode 100644 index 00000000..b9f2c4e8 --- /dev/null +++ b/main/src/main/java/org/onap/policy/pap/main/rest/stub/PolicyAuditControllerV1Stub.java @@ -0,0 +1,86 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2023 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.pap.main.rest.stub; + +import java.util.List; +import java.util.UUID; +import javax.validation.Valid; +import javax.validation.constraints.Max; +import javax.validation.constraints.Min; +import lombok.RequiredArgsConstructor; +import org.onap.policy.models.pap.concepts.PolicyAudit; +import org.onap.policy.pap.main.rest.PapRestControllerV1; +import org.onap.policy.pap.main.rest.PolicyAuditControllerV1Api; +import org.springframework.context.annotation.Profile; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequiredArgsConstructor +@Profile("stub") +public class PolicyAuditControllerV1Stub extends PapRestControllerV1 + implements PolicyAuditControllerV1Api { + + private final StubUtils stubUtils; + + @Override + public ResponseEntity<List<PolicyAudit>> getAllAuditRecords( + UUID requestId, + @Min(1) @Max(100) @Valid Integer recordCount, + @Valid Long startTime, + @Valid Long endTime) { + return stubUtils.getStubbedResponseList(PolicyAudit.class); + } + + @Override + public ResponseEntity<Object> getAuditRecordsByGroup( + String pdpGroupName, + UUID requestId, + @Min(1) @Max(100) @Valid Integer recordCount, + @Valid Long startTime, + @Valid Long endTime) { + return stubUtils.getStubbedResponse(Object.class); + } + + @Override + public ResponseEntity<Object> getAuditRecordsOfPolicy( + String policyName, + String policyVersion, + UUID requestId, + @Min(1) @Max(100) @Valid Integer recordCount, + @Valid Long startTime, + @Valid Long endTime) { + return stubUtils.getStubbedResponse(Object.class); + } + + @Override + public ResponseEntity<Object> getAuditRecordsOfPolicyinPdpGroup( + String pdpGroupName, + String policyName, + String policyVersion, + UUID requestId, + @Min(1) @Max(100) @Valid Integer recordCount, + @Valid Long startTime, + @Valid Long endTime) { + return stubUtils.getStubbedResponse(Object.class); + } + +}
\ No newline at end of file diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/stub/PolicyComponentsHealthCheckControllerV1Stub.java b/main/src/main/java/org/onap/policy/pap/main/rest/stub/PolicyComponentsHealthCheckControllerV1Stub.java new file mode 100644 index 00000000..16773fa0 --- /dev/null +++ b/main/src/main/java/org/onap/policy/pap/main/rest/stub/PolicyComponentsHealthCheckControllerV1Stub.java @@ -0,0 +1,45 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2023 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.pap.main.rest.stub; + +import java.util.Map; +import java.util.UUID; +import lombok.RequiredArgsConstructor; +import org.onap.policy.pap.main.rest.PapRestControllerV1; +import org.onap.policy.pap.main.rest.PolicyComponentsHealthCheckControllerV1Api; +import org.springframework.context.annotation.Profile; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequiredArgsConstructor +@Profile("stub") +public class PolicyComponentsHealthCheckControllerV1Stub extends PapRestControllerV1 + implements PolicyComponentsHealthCheckControllerV1Api { + + private final StubUtils stubsUtils; + + @Override + public ResponseEntity<Map<String, Object>> policyComponentsHealthCheck(UUID requestId) { + return stubsUtils.getStubbedResponseMap(); + } + +} diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/stub/PolicyStatusControllerV1Stub.java b/main/src/main/java/org/onap/policy/pap/main/rest/stub/PolicyStatusControllerV1Stub.java new file mode 100644 index 00000000..323320ab --- /dev/null +++ b/main/src/main/java/org/onap/policy/pap/main/rest/stub/PolicyStatusControllerV1Stub.java @@ -0,0 +1,79 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2023 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.pap.main.rest.stub; + +import java.util.UUID; +import javax.validation.Valid; +import lombok.RequiredArgsConstructor; +import org.onap.policy.pap.main.rest.PapRestControllerV1; +import org.onap.policy.pap.main.rest.PolicyStatusControllerV1Api; +import org.springframework.context.annotation.Profile; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequiredArgsConstructor +@Profile("stub") +public class PolicyStatusControllerV1Stub extends PapRestControllerV1 + implements PolicyStatusControllerV1Api { + + private final StubUtils stubUtils; + + @Override + public ResponseEntity<Object> getStatusOfAllPolicies(UUID requestId) { + return stubUtils.getStubbedResponse(Object.class); + } + + @Override + public ResponseEntity<Object> getStatusOfPolicies( + String pdpGroupName, String policyName, UUID requestId) { + return stubUtils.getStubbedResponse(Object.class); + } + + @Override + public ResponseEntity<Object> getStatusOfPoliciesByGroup( + String pdpGroupName, UUID requestId, @Valid String regex) { + return stubUtils.getStubbedResponse(Object.class); + } + + @Override + public ResponseEntity<Object> getStatusOfPolicy( + String pdpGroupName, String policyName, String policyVersion, UUID requestId) { + return stubUtils.getStubbedResponse(Object.class); + } + + @Override + public ResponseEntity<Object> queryAllDeployedPolicies(UUID requestId, @Valid String regex) { + return stubUtils.getStubbedResponse(Object.class); + } + + @Override + public ResponseEntity<Object> queryDeployedPolicies(String name, UUID requestId) { + return stubUtils.getStubbedResponse(Object.class); + } + + @Override + public ResponseEntity<Object> queryDeployedPolicy( + String name, String version, UUID requestId) { + return stubUtils.getStubbedResponse(Object.class); + } + +} diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/stub/StatisticsRestControllerV1Stub.java b/main/src/main/java/org/onap/policy/pap/main/rest/stub/StatisticsRestControllerV1Stub.java new file mode 100644 index 00000000..663f1acc --- /dev/null +++ b/main/src/main/java/org/onap/policy/pap/main/rest/stub/StatisticsRestControllerV1Stub.java @@ -0,0 +1,88 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2023 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.pap.main.rest.stub; + +import java.util.List; +import java.util.Map; +import java.util.UUID; +import javax.validation.Valid; +import lombok.RequiredArgsConstructor; +import org.onap.policy.models.pdp.concepts.PdpStatistics; +import org.onap.policy.pap.main.rest.PapRestControllerV1; +import org.onap.policy.pap.main.rest.StatisticsReport; +import org.onap.policy.pap.main.rest.StatisticsRestControllerV1Api; +import org.springframework.context.annotation.Profile; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequiredArgsConstructor +@Profile("stub") +public class StatisticsRestControllerV1Stub extends PapRestControllerV1 + implements StatisticsRestControllerV1Api { + + private final StubUtils stubUtils; + + @Override + public ResponseEntity<Map<String, Map<String, List<PdpStatistics>>>> pdpGroupStatistics( + String group, + UUID requestId, + @Valid Integer recordCount, + @Valid Long startTime, + @Valid Long endTime) { + return stubUtils.getStubbedResponseStatistics(); + } + + @Override + public ResponseEntity<Map<String, Map<String, List<PdpStatistics>>>> pdpInstanceStatistics( + String group, + String type, + String pdp, + UUID requestId, + @Valid Integer recordCount, + @Valid Long startTime, + @Valid Long endTime) { + return stubUtils.getStubbedResponseStatistics(); + } + + @Override + public ResponseEntity<Map<String, Map<String, List<PdpStatistics>>>> pdpStatistics( + UUID requestId, @Valid Integer recordCount, @Valid Long startTime, @Valid Long endTime) { + return stubUtils.getStubbedResponseStatistics(); + } + + @Override + public ResponseEntity<Map<String, Map<String, List<PdpStatistics>>>> pdpSubGroupStatistics( + String group, + String type, + UUID requestId, + @Valid Integer recordCount, + @Valid Long startTime, + @Valid Long endTime) { + return stubUtils.getStubbedResponseStatistics(); + } + + @Override + public ResponseEntity<StatisticsReport> statistics(UUID requestId) { + return stubUtils.getStubbedResponse(StatisticsReport.class); + } + +} diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/stub/StubUtils.java b/main/src/main/java/org/onap/policy/pap/main/rest/stub/StubUtils.java new file mode 100644 index 00000000..d2ab15fb --- /dev/null +++ b/main/src/main/java/org/onap/policy/pap/main/rest/stub/StubUtils.java @@ -0,0 +1,112 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2023 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.pap.main.rest.stub; + +import com.google.gson.Gson; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import javax.servlet.http.HttpServletRequest; +import lombok.RequiredArgsConstructor; +import org.onap.policy.models.pdp.concepts.PdpStatistics; +import org.onap.policy.pap.main.rest.PapRestControllerV1; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.context.annotation.Profile; +import org.springframework.core.io.ClassPathResource; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Service; + +@RequiredArgsConstructor +@Service +@Profile("stub") +class StubUtils { + private static final Logger log = LoggerFactory.getLogger(StubUtils.class); + private final HttpServletRequest request; + private static final String ACCEPT = "Accept"; + private static final String PAP_DB = + "/PapDb.json"; + private static final Gson JSON_TRANSLATOR = new Gson(); + + <T> ResponseEntity<T> getStubbedResponse(Class<T> clazz) { + var accept = request.getHeader(ACCEPT); + if (accept != null && accept.contains("application/json")) { + final var resource = new ClassPathResource(PAP_DB); + try (var inputStream = resource.getInputStream()) { + final var string = new String(inputStream.readAllBytes(), StandardCharsets.UTF_8); + var targetObject = JSON_TRANSLATOR.fromJson(string, clazz); + return new ResponseEntity<>(targetObject, HttpStatus.OK); + } catch (IOException e) { + log.error("Couldn't serialize response for content type application/json", e); + return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); + } + } + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + } + + <T> ResponseEntity<List<T>> getStubbedResponseList(Class<T> clazz) { + var accept = request.getHeader(ACCEPT); + if (accept != null && accept.contains("application/json")) { + final var resource = new ClassPathResource(PAP_DB); + try (var inputStream = resource.getInputStream()) { + final var string = new String(inputStream.readAllBytes(), StandardCharsets.UTF_8); + var targetObject = Arrays.asList(JSON_TRANSLATOR.fromJson(string, clazz)); + return new ResponseEntity<>(targetObject, HttpStatus.OK); + } catch (IOException e) { + log.error("Couldn't serialize response for content type application/json", e); + return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); + } + } + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + } + + ResponseEntity<Map<String, Object>> getStubbedResponseMap() { + var accept = request.getHeader(ACCEPT); + if (accept != null && accept.contains("application/json")) { + final var resource = new ClassPathResource(PAP_DB); + try (var inputStream = resource.getInputStream()) { + Map<String, Object> map = new HashMap<>(); + final var string = new String(inputStream.readAllBytes(), StandardCharsets.UTF_8); + map.put(PapRestControllerV1.API_VERSION_NAME, + JSON_TRANSLATOR.fromJson(string, Object.class)); + return new ResponseEntity<>(map, HttpStatus.OK); + } catch (IOException e) { + log.error("Couldn't serialize response for content type application/json", e); + return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); + } + } + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + } + + ResponseEntity<Map<String, Map<String, List<PdpStatistics>>>> getStubbedResponseStatistics() { + var accept = request.getHeader(ACCEPT); + if (accept != null && accept.contains("application/json")) { + Map<String, Map<String, List<PdpStatistics>>> map = new HashMap<>(); + return new ResponseEntity<>(map, HttpStatus.OK); + } + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + } + +} |