summaryrefslogtreecommitdiffstats
path: root/sdc-os-chef/sdc-frontend/startup.sh
AgeCommit message (Expand)AuthorFilesLines
2017-12-31SDC Designers Integration - Part 1Idan Amit1-1/+1
2017-12-10Final commit to master merge fromTal Gitelman1-1/+1
2017-12-07clean up and update docker run scriptIdan Amit1-1/+1
2017-08-07[SDC] syncTal Gitelman1-1/+1
2017-02-20Fix UI and dockerml636r1-0/+1
2017-02-19Initial OpenECOMP SDC commitMichael Lando1-0/+12
='n102' href='#n102'>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 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
/*-
 * ============LICENSE_START=======================================================
 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
 * Modifications Copyright (C) 2020 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.pdpx.main.parameters;

import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import org.junit.Test;
import org.onap.policy.pdpx.main.PolicyXacmlPdpException;
import org.onap.policy.pdpx.main.startstop.XacmlPdpCommandLineArguments;

/**
 * Class to perform unit test of XacmlPdpParameterHandler.
 *
 */
public class TestXacmlPdpParameterHandler {
    @Test
    public void testParameterHandlerNoParameterFile() throws PolicyXacmlPdpException {
        final String[] noArgumentString = {"-c", "parameters/NoParameterFile.json"};

        final XacmlPdpCommandLineArguments noArguments = new XacmlPdpCommandLineArguments();
        noArguments.parse(noArgumentString);

        assertThatThrownBy(() -> new XacmlPdpParameterHandler().getParameters(noArguments))
                .isInstanceOf(PolicyXacmlPdpException.class);
    }

    @Test
    public void testParameterHandlerEmptyParameters() throws PolicyXacmlPdpException {
        final String[] emptyArgumentString = {"-c", "parameters/EmptyParameters.json"};

        final XacmlPdpCommandLineArguments emptyArguments = new XacmlPdpCommandLineArguments();
        emptyArguments.parse(emptyArgumentString);

        assertThatThrownBy(() -> new XacmlPdpParameterHandler().getParameters(emptyArguments))
                .hasMessage("no parameters found in \"parameters/EmptyParameters.json\"");
    }

    @Test
    public void testParameterHandlerBadParameters() throws PolicyXacmlPdpException {
        final String[] badArgumentString = {"-c", "parameters/BadParameters.json"};

        final XacmlPdpCommandLineArguments badArguments = new XacmlPdpCommandLineArguments();
        badArguments.parse(badArgumentString);

        assertThatThrownBy(() -> new XacmlPdpParameterHandler().getParameters(badArguments))
                .hasMessage("error reading parameters from \"parameters/BadParameters.json\"\n"
                        + "(JsonSyntaxException):java.lang.IllegalStateException: "
                        + "Expected a string but was BEGIN_ARRAY at line 2 column 14 path $.name");

    }

    @Test
    public void testParameterHandlerInvalidParameters() throws PolicyXacmlPdpException {
        final String[] invalidArgumentString = {"-c", "parameters/InvalidParameters.json"};

        final XacmlPdpCommandLineArguments invalidArguments = new XacmlPdpCommandLineArguments();
        invalidArguments.parse(invalidArgumentString);

        assertThatThrownBy(() -> new XacmlPdpParameterHandler().getParameters(invalidArguments))
                .hasMessage("error reading parameters from \"parameters/InvalidParameters.json\"\n"
                        + "(JsonSyntaxException):java.lang.IllegalStateException: "
                        + "Expected a string but was BEGIN_ARRAY at line 2 column 14 path $.name");
    }

    @Test
    public void testParameterHandlerNoParameters() throws PolicyXacmlPdpException {
        final String[] noArgumentString = {"-c", "parameters/NoParameters.json"};

        final XacmlPdpCommandLineArguments noArguments = new XacmlPdpCommandLineArguments();
        noArguments.parse(noArgumentString);

        assertThatThrownBy(() -> new XacmlPdpParameterHandler().getParameters(noArguments))
                .hasMessage("validation error(s) on parameters from \"parameters/NoParameters.json\"\n"
                        + "parameter group \"null\" type "
                        + "\"org.onap.policy.pdpx.main.parameters.XacmlPdpParameterGroup\""
                        + " INVALID, parameter group has status INVALID\n"
                        + "  field \"name\" type \"java.lang.String\" value \"null\" INVALID, "
                        + "must be a non-blank string\n"
                        + "  field \"pdpGroup\" type \"java.lang.String\" value \"null\" INVALID, "
                        + "must be a non-blank string\n"
                        + "  field \"applicationPath\" type \"java.lang.String\" value \"null\" INVALID, "
                        + "must have application path for applications to store policies and data.\n");
    }

    @Test
    public void testParameterHandlerMinumumParameters() throws PolicyXacmlPdpException {
        final String[] minArgumentString = {"-c", "parameters/MinimumParameters.json"};

        final XacmlPdpCommandLineArguments minArguments = new XacmlPdpCommandLineArguments();
        minArguments.parse(minArgumentString);

        final XacmlPdpParameterGroup parGroup = new XacmlPdpParameterHandler().getParameters(minArguments);
        assertEquals(CommonTestData.PDPX_PARAMETER_GROUP_NAME, parGroup.getName());
        assertEquals(CommonTestData.PDPX_GROUP, parGroup.getPdpGroup());
    }

    @Test
    public void testXacmlPdpParameterGroup() throws PolicyXacmlPdpException {
        final String[] xacmlPdpConfigParameters = {"-c", "parameters/XacmlPdpConfigParameters.json"};

        final XacmlPdpCommandLineArguments arguments = new XacmlPdpCommandLineArguments();
        arguments.parse(xacmlPdpConfigParameters);

        final XacmlPdpParameterGroup parGroup = new XacmlPdpParameterHandler().getParameters(arguments);
        assertTrue(arguments.checkSetConfigurationFilePath());
        assertEquals(CommonTestData.PDPX_PARAMETER_GROUP_NAME, parGroup.getName());
        assertEquals(CommonTestData.PDPX_GROUP, parGroup.getPdpGroup());
    }

    @Test
    public void testXacmlPdpParameterGroup_InvalidName() throws PolicyXacmlPdpException {
        final String[] xacmlPdpConfigParameters = {"-c", "parameters/XacmlPdpConfigParameters_InvalidName.json"};

        final XacmlPdpCommandLineArguments arguments = new XacmlPdpCommandLineArguments();
        arguments.parse(xacmlPdpConfigParameters);

        assertThatThrownBy(() -> new XacmlPdpParameterHandler().getParameters(arguments)).hasMessageContaining(
                "field \"name\" type \"java.lang.String\" value \" \" INVALID, must be a non-blank string");
    }

    @Test
    public void testXacmlPdpParameterGroup_InvalidPdpGroup() throws PolicyXacmlPdpException {
        final String[] xacmlPdpConfigParameters = {"-c", "parameters/XacmlPdpConfigParameters_InvalidPdpGroup.json"};

        final XacmlPdpCommandLineArguments arguments = new XacmlPdpCommandLineArguments();
        arguments.parse(xacmlPdpConfigParameters);

        assertThatThrownBy(() -> new XacmlPdpParameterHandler().getParameters(arguments)).hasMessageContaining(
                "field \"pdpGroup\" type \"java.lang.String\" value \" \" INVALID, must be a non-blank string");
    }

    @Test
    public void testXacmlPdpParameterGroup_InvalidRestServerParameters() throws PolicyXacmlPdpException, IOException {
        final String[] xacmlPdpConfigParameters =
            {"-c", "parameters/XacmlPdpConfigParameters_InvalidRestServerParameters.json"};

        final XacmlPdpCommandLineArguments arguments = new XacmlPdpCommandLineArguments();
        arguments.parse(xacmlPdpConfigParameters);

        new String(Files.readAllBytes(
                Paths.get("src/test/resources/expectedValidationResults/InvalidRestServerParameters.txt")));

        assertThatThrownBy(() -> new XacmlPdpParameterHandler().getParameters(arguments))
                .hasMessageContaining("validation error(s) on parameters from "
                        + "\"parameters/XacmlPdpConfigParameters_InvalidRestServerParameters.json\"");
    }

    @Test
    public void testXacmlPdpVersion() throws PolicyXacmlPdpException {
        final String[] xacmlPdpConfigParameters = {"-v"};
        final XacmlPdpCommandLineArguments arguments = new XacmlPdpCommandLineArguments();
        final String version = arguments.parse(xacmlPdpConfigParameters);
        assertTrue(version.startsWith("ONAP Policy Framework Xacml PDP Service"));
    }

    @Test
    public void testXacmlPdpHelp() throws PolicyXacmlPdpException {
        final String[] xacmlPdpConfigParameters = {"-h"};
        final XacmlPdpCommandLineArguments arguments = new XacmlPdpCommandLineArguments();
        final String help = arguments.parse(xacmlPdpConfigParameters);
        assertTrue(help.startsWith("usage:"));
    }

    @Test
    public void testXacmlPdpInvalidOption() {
        final String[] xacmlPdpConfigParameters = {"-d"};
        final XacmlPdpCommandLineArguments arguments = new XacmlPdpCommandLineArguments();
        assertThatThrownBy(() ->
            arguments.parse(xacmlPdpConfigParameters)
        ).isInstanceOf(PolicyXacmlPdpException.class)
        .hasMessageContaining("invalid command line arguments specified");
    }
}