summaryrefslogtreecommitdiffstats
path: root/openecomp-ui/resources/scss/components/_forms.scss
AgeCommit message (Expand)AuthorFilesLines
2017-12-21Add collaboration featuretalig1-2/+2
2017-07-18[SDC] Onboarding 1710 rebase.Avi Ziv1-1/+1
2017-06-09[SDC-29] Amdocs OnBoard 1707 initial commit.AviZi1-9/+40
2017-02-19Add new code new versionMichael Lando1-0/+45
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 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 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271
/*-
 * ============LICENSE_START=======================================================
 * SDC
 * ================================================================================
 * Copyright (C) 2017 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.openecomp.sdc.vendorsoftwareproduct.services.schemagenerator;

import org.everit.json.schema.EmptySchema;
import org.everit.json.schema.loader.SchemaLoader;
import org.json.JSONObject;
import org.openecomp.core.utilities.json.JsonUtil;
import org.openecomp.sdc.vendorsoftwareproduct.services.schemagenerator.SchemaGenerator;
import org.openecomp.sdc.vendorsoftwareproduct.types.composition.ComponentData;
import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityType;
import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Network;
import org.openecomp.sdc.vendorsoftwareproduct.types.composition.NetworkType;
import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Nic;
import org.openecomp.sdc.vendorsoftwareproduct.types.schemagenerator.ComponentCompositionSchemaInput;
import org.openecomp.sdc.vendorsoftwareproduct.types.schemagenerator.ComponentQuestionnaireSchemaInput;
import org.openecomp.sdc.vendorsoftwareproduct.types.schemagenerator.NetworkCompositionSchemaInput;
import org.openecomp.sdc.vendorsoftwareproduct.types.schemagenerator.NicCompositionSchemaInput;
import org.openecomp.sdc.vendorsoftwareproduct.types.schemagenerator.SchemaTemplateContext;
import org.testng.Assert;
import org.testng.annotations.Test;

import java.util.Arrays;
import java.util.Map;

public class SchemaGeneratorTest {
  /*

  private static int getMinOfVmMax(JSONObject schemaJson) {
    return schemaJson.getJSONObject("properties").getJSONObject("compute")
        .getJSONObject("properties").getJSONObject("numOfVMs").getJSONObject("properties")
        .getJSONObject("maximum").getInt("minimum");
  }

  private static JSONObject validateSchema(String schema) {
    System.out.println(schema);
    Assert.assertNotNull(schema);
    Assert.assertTrue(JsonUtil.isValidJson(schema));
    JSONObject schemaJson = new JSONObject(schema);
    Assert.assertFalse(SchemaLoader.load(schemaJson) instanceof EmptySchema);
    return schemaJson;
  }

  // TODO: 3/15/2017 fix and enable   //@Test
  public void testGenerateVspQuestionnaire() {
    String schema = SchemaGenerator
        .generate(SchemaTemplateContext.questionnaire, CompositionEntityType.vsp, null);
    validateSchema(schema);
  }

  @Test
  public void testGenerateNetworkCompositionUpload() {
    Network network = new Network();
    network.setName("upload network1 name");
    network.setDhcp(true);

    NetworkCompositionSchemaInput input = new NetworkCompositionSchemaInput();
    input.setManual(false);
    input.setNetwork(network);

    String schema = SchemaGenerator
        .generate(SchemaTemplateContext.composition, CompositionEntityType.network, input);
    validateSchema(schema);
  }

  @Test
  public void testGenerateNetworkCompositionManual() {
    NetworkCompositionSchemaInput input = new NetworkCompositionSchemaInput();
    input.setManual(true);

    String schema = SchemaGenerator
        .generate(SchemaTemplateContext.composition, CompositionEntityType.network, input);

    validateSchema(schema);
  }

  @Test
  public void testGenerateComponentQuestionnaireWithoutInput() {
    String schema = SchemaGenerator
        .generate(SchemaTemplateContext.questionnaire, CompositionEntityType.component, null);
    validateSchema(schema);
  }

  @Test
  public void testGenerateComponentQuestionnaireWithMissingInput() {
    ComponentQuestionnaireSchemaInput
        input = new ComponentQuestionnaireSchemaInput(Arrays.asList("nic1", "nic2"),
        JsonUtil.json2Object("{\n" +
            "  \"compute\": {\n" +
            "    \"numOfVMs\": {\n" +
            "      \"blabla\": 70\n" + // no minimum
            "    }\n" +
            "  }\n" +
            "}", Map.class));
    String schema = SchemaGenerator
        .generate(SchemaTemplateContext.questionnaire, CompositionEntityType.component, input);
    JSONObject schemaJson = validateSchema(schema);
    //Assert.assertEquals(getMinOfVmMax(schemaJson), 0);
  }

  @Test
  public void testGenerateComponentQuestionnaireWithInvalidTypeInput() {
    ComponentQuestionnaireSchemaInput input =
        new ComponentQuestionnaireSchemaInput(Arrays.asList("nic1", "nic2"),
            JsonUtil.json2Object("{\n" +
                "  \"compute\": {\n" +
                "    \"numOfVMs\": {\n" +
                "      \"minimum\": \"some string instead of integer\"\n" +
                // invalid minimum - string
                "    }\n" +
                "  }\n" +
                "}", Map.class));
    String schema = SchemaGenerator
        .generate(SchemaTemplateContext.questionnaire, CompositionEntityType.component, input);
    JSONObject schemaJson = validateSchema(schema);
    Assert.assertEquals(getMinOfVmMax(schemaJson), 0);
  }

  @Test
  public void testGenerateComponentQuestionnaireWithInvalidRangeInput() {
    ComponentQuestionnaireSchemaInput input =
        new ComponentQuestionnaireSchemaInput(Arrays.asList("nic1", "nic2"),
            JsonUtil.json2Object("{\n" +
                "  \"compute\": {\n" +
                "    \"numOfVMs\": {\n" +
                "      \"minimum\": 150\n" + // invalid minimum - integer out of range (0-100)
                "    }\n" +
                "  }\n" +
                "}", Map.class));
    String schema = SchemaGenerator
        .generate(SchemaTemplateContext.questionnaire, CompositionEntityType.component, input);
    JSONObject schemaJson = validateSchema(schema);
    Assert.assertEquals(getMinOfVmMax(schemaJson), 0);
  }

  @Test
  public void testGenerateComponentQuestionnaireWithValidInput() {
    ComponentQuestionnaireSchemaInput input =
        new ComponentQuestionnaireSchemaInput(Arrays.asList("nic1", "nic2"),
            JsonUtil.json2Object("{\n" +
                "  \"compute\": {\n" +
                "    \"numOfVMs\": {\n" +
                "      \"minimum\": 30\n" + // valid minimum - integer at the correct range (0-100)
                "    }\n" +
                "  }\n" +
                "}", Map.class));
    String schema = SchemaGenerator
        .generate(SchemaTemplateContext.questionnaire, CompositionEntityType.component, input);
    JSONObject schemaJson = validateSchema(schema);
    Assert.assertEquals(getMinOfVmMax(schemaJson), 30);
  }

  @Test
  public void testGenerateNicQuestionnaire() {
    String schema = SchemaGenerator
        .generate(SchemaTemplateContext.questionnaire, CompositionEntityType.nic, null);
    validateSchema(schema);
  }

  @Test
  public void testGenerateComponentCompositionUpload() {
    ComponentData component = new ComponentData();
    component.setName("upload comp1 name");
    component.setDescription("upload comp1 desc");

    ComponentCompositionSchemaInput input = new ComponentCompositionSchemaInput();
    input.setManual(false);
    input.setComponent(component);

    String schema = SchemaGenerator
        .generate(SchemaTemplateContext.composition, CompositionEntityType.component, input);
    validateSchema(schema);
  }

  @Test
  public void testGenerateComponentCompositionManual() {
    ComponentCompositionSchemaInput input = new ComponentCompositionSchemaInput();
    input.setManual(true);

    String schema = SchemaGenerator
        .generate(SchemaTemplateContext.composition, CompositionEntityType.component, input);
    validateSchema(schema);
  }

  @Test
  public void testGenerateNicCompositionUpload() {
    Nic nic = new Nic();
    nic.setName("upload nic1 name");
    nic.setDescription("upload nic1 desc");
    nic.setNetworkId("upload nic1 networkId");
    //nic.setNetworkName("upload nic1 networkName");
    nic.setNetworkType(NetworkType.External);

    NicCompositionSchemaInput input = new NicCompositionSchemaInput();
    input.setManual(false);
    input.setNic(nic);

    String schema = SchemaGenerator
        .generate(SchemaTemplateContext.composition, CompositionEntityType.nic, input);
    validateSchema(schema);
  }


//    @Test
//    public void testGenerateNicCompositionManualWithoutNetworkId() {
//        Nic nic = new Nic();
//        nic.setName("upload nic1 name");
//        nic.setDescription("upload nic1 desc");
//        //nic.setNetworkName("upload nic1 networkName");
//        nic.setNetworkType(NetworkType.External);
//
//        NicCompositionSchemaInput input = new NicCompositionSchemaInput();
//        input.setManual(true);
//        input.setNic(nic);
//
//        String schema = SchemaGenerator.generate(SchemaTemplateContext.composition, CompositionEntityType.nic, input);
//        validateSchema(schema);
//    }

  @Test
  public void testGenerateNicCompositionUploadWithoutNetworkId() {
    Nic nic = new Nic();
    nic.setName("upload nic1 name");
    nic.setDescription("upload nic1 desc");
    //nic.setNetworkName("upload nic1 networkName");
    nic.setNetworkType(NetworkType.External);

    NicCompositionSchemaInput input = new NicCompositionSchemaInput();
    input.setManual(false);
    input.setNic(nic);

    String schema = SchemaGenerator
        .generate(SchemaTemplateContext.composition, CompositionEntityType.nic, input);
    validateSchema(schema);
  }

  @Test
  public void testGenerateNicCompositionManual() {Nic nic = new Nic();
    nic.setName("upload nic1 name");
    nic.setDescription("upload nic1 desc");
    nic.setNetworkType(NetworkType.Internal);
    NicCompositionSchemaInput input = new NicCompositionSchemaInput();

    input.setManual(true);
    input.setNetworkIds(
        Arrays.asList("manual networkId1", "manual networkId2", "manual networkId3"));
    input.setNic(nic);
    String schema = SchemaGenerator
        .generate(SchemaTemplateContext.composition, CompositionEntityType.nic, input);
    validateSchema(schema);
  }
  */
}