aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-ui/src/app/ng2/pages/attributes-outputs
diff options
context:
space:
mode:
authorimamSidero <imam.hussain@est.tech>2023-01-11 18:13:25 +0000
committerMichael Morris <michael.morris@est.tech>2023-01-13 13:22:26 +0000
commita8d208b231237fc9f05f83c2b33fa207d58f1480 (patch)
treee58cac7c4a5e81e5fd042ed244539d4981947434 /catalog-ui/src/app/ng2/pages/attributes-outputs
parentaa92493c97b43075c18696d79f7d1bf62aa4805a (diff)
Provide tosca function as map primitive type entry values in composition view
Providing the capability to add tosca function as the primitive type entry values of map in composition view Issue-ID: SDC-4319 Signed-off-by: Imam hussain <imam.hussain@est.tech> Change-Id: I5cf67bc94ac5c72be6a962e07160329cd07d302c
Diffstat (limited to 'catalog-ui/src/app/ng2/pages/attributes-outputs')
0 files changed, 0 insertions, 0 deletions
'#n91'>91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
/*-
 * ============LICENSE_START=======================================================
 * Copyright (C) 2019 Bell Canada.
 * Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
 * ================================================================================
 * 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.
 * ============LICENSE_END=========================================================
 */

package org.onap.policy.cds.client;

import static org.assertj.core.api.Assertions.assertThatCode;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;

import io.grpc.ManagedChannel;
import io.grpc.inprocess.InProcessChannelBuilder;
import io.grpc.inprocess.InProcessServerBuilder;
import io.grpc.stub.StreamObserver;
import io.grpc.testing.GrpcCleanupRule;
import io.grpc.util.MutableHandlerRegistry;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.onap.ccsdk.cds.controllerblueprints.common.api.ActionIdentifiers;
import org.onap.ccsdk.cds.controllerblueprints.processing.api.BluePrintProcessingServiceGrpc.BluePrintProcessingServiceImplBase;
import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceInput;
import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceOutput;
import org.onap.policy.cds.api.CdsProcessorListener;
import org.onap.policy.cds.api.TestCdsProcessorListenerImpl;
import org.onap.policy.cds.properties.CdsServerProperties;

public class CdsProcessorGrpcClientTest {

    // Generate a unique in-process server name.
    private static final String SERVER_NAME = InProcessServerBuilder.generateName();

    // Manages automatic graceful shutdown for the registered server and client channels at the end of test.
    @Rule
    public final GrpcCleanupRule grpcCleanup = new GrpcCleanupRule();

    private final CdsProcessorListener listener = spy(new TestCdsProcessorListenerImpl());
    private final CdsServerProperties props = new CdsServerProperties();
    private final MutableHandlerRegistry serviceRegistry = new MutableHandlerRegistry();
    private final AtomicReference<StreamObserver<ExecutionServiceOutput>> responseObserverRef = new AtomicReference<>();
    private final List<String> messagesDelivered = new ArrayList<>();
    private final CountDownLatch allRequestsDelivered = new CountDownLatch(1);

    private CdsProcessorGrpcClient client;

    /**
     * Setup the test.
     *
     * @throws IOException on failure to register the test grpc server for graceful shutdown
     */
    @Before
    public void setUp() throws IOException {
        // Setup the CDS properties
        props.setHost(SERVER_NAME);
        props.setPort(2000);
        props.setUsername("testUser");
        props.setPassword("testPassword");
        props.setTimeout(60);

        // Create a server, add service, start, and register for automatic graceful shutdown.
        grpcCleanup.register(InProcessServerBuilder.forName(SERVER_NAME)
            .fallbackHandlerRegistry(serviceRegistry).directExecutor().build().start());

        // Create a client channel and register for automatic graceful shutdown
        ManagedChannel channel = grpcCleanup
            .register(InProcessChannelBuilder.forName(SERVER_NAME).directExecutor().build());

        // Create an instance of the gRPC client
        client = new CdsProcessorGrpcClient(channel, new CdsProcessorHandler(listener, "gRPC://localhost:1234/"));

        // Implement the test gRPC server
        BluePrintProcessingServiceImplBase testCdsBlueprintServerImpl = new BluePrintProcessingServiceImplBase() {
            @Override
            public StreamObserver<ExecutionServiceInput> process(
                final StreamObserver<ExecutionServiceOutput> responseObserver) {
                responseObserverRef.set(responseObserver);

                return new StreamObserver<ExecutionServiceInput>() {
                    @Override
                    public void onNext(final ExecutionServiceInput executionServiceInput) {
                        messagesDelivered.add(executionServiceInput.getActionIdentifiers().getActionName());
                    }

                    @Override
                    public void onError(final Throwable throwable) {
                        // Test method
                    }

                    @Override
                    public void onCompleted() {
                        allRequestsDelivered.countDown();
                    }
                };
            }
        };
        serviceRegistry.addService(testCdsBlueprintServerImpl);
    }

    @After
    public void tearDown() {
        client.close();
    }

    @Test
    public void testCdsProcessorGrpcClientConstructor() {
        assertThatCode(() -> new CdsProcessorGrpcClient(listener, props).close()).doesNotThrowAnyException();
    }

    @Test(expected = IllegalStateException.class)
    public void testCdsProcessorGrpcClientConstructorFailure() {
        props.setHost(null);
        new CdsProcessorGrpcClient(listener, props).close();
    }

    @Test
    public void testSendRequestFail() throws InterruptedException {
        // Setup
        ExecutionServiceInput testReq = ExecutionServiceInput.newBuilder()
            .setActionIdentifiers(ActionIdentifiers.newBuilder().setActionName("policy-to-cds").build())
            .build();

        // Act
        CountDownLatch finishLatch = client.sendRequest(testReq);
        responseObserverRef.get().onError(new Throwable("failed to send testReq."));

        verify(listener).onError(any(Throwable.class));
        assertTrue(finishLatch.await(0, TimeUnit.SECONDS));
    }

    @Test
    public void testSendRequestSuccess() throws InterruptedException {
        // Setup request
        ExecutionServiceInput testReq1 = ExecutionServiceInput.newBuilder()
            .setActionIdentifiers(ActionIdentifiers.newBuilder().setActionName("policy-to-cds-req1").build()).build();

        // Act
        final CountDownLatch finishLatch = client.sendRequest(testReq1);

        // Assert that request message was sent and delivered once to the server
        assertTrue(allRequestsDelivered.await(1, TimeUnit.SECONDS));
        assertEquals(Collections.singletonList("policy-to-cds-req1"), messagesDelivered);

        // Setup the server to send out two simple response messages and verify that the client receives them.
        ExecutionServiceOutput testResp1 = ExecutionServiceOutput.newBuilder()
            .setActionIdentifiers(ActionIdentifiers.newBuilder().setActionName("policy-to-cds-resp1").build()).build();
        ExecutionServiceOutput testResp2 = ExecutionServiceOutput.newBuilder()
            .setActionIdentifiers(ActionIdentifiers.newBuilder().setActionName("policy-to-cds-resp2").build()).build();
        responseObserverRef.get().onNext(testResp1);
        verify(listener).onMessage(testResp1);
        responseObserverRef.get().onNext(testResp2);
        verify(listener).onMessage(testResp2);

        // let server complete.
        responseObserverRef.get().onCompleted();
        assertTrue(finishLatch.await(0, TimeUnit.SECONDS));
    }
}