Beispiel #1
0
  @Test
  public void controllerAugmentationTest() throws Exception {
    File cn =
        new File(getClass().getResource("/controller-models/controller-network.yang").toURI());
    File co =
        new File(getClass().getResource("/controller-models/controller-openflow.yang").toURI());
    File ietfInetTypes = new File(getClass().getResource("/ietf/ietf-inet-types.yang").toURI());

    final SchemaContext context = YangParserTestUtils.parseYangSources(cn, co, ietfInetTypes);
    assertNotNull("Schema Context is null", context);

    final BindingGenerator bindingGen = new BindingGeneratorImpl(true);
    final List<Type> genTypes = bindingGen.generateTypes(context);

    assertNotNull(genTypes);
    assertTrue(!genTypes.isEmpty());
  }
  @Test
  public void testGeneretedTypesBitsTest() throws Exception {
    final URI yangTypesPath = getClass().getResource("/simple-bits-demo.yang").toURI();

    final SchemaContext context = RetestUtils.parseYangSources(new File(yangTypesPath));
    assertTrue(context != null);

    final BindingGenerator bindingGen = new BindingGeneratorImpl(true);
    final List<Type> genTypes = bindingGen.generateTypes(context);
    assertTrue(genTypes != null);

    List<MethodSignature> methodSignaturesList = null;

    boolean leafParentFound = false;

    boolean byteTypeFound = false;
    int classPropertiesNumb = 0;
    int toStringPropertiesNum = 0;
    int equalPropertiesNum = 0;
    int hashPropertiesNum = 0;

    String nameReturnParamType = "";
    boolean getByteLeafMethodFound = false;
    boolean setByteLeafMethodFound = false;
    int setByteLeafMethodParamNum = 0;

    for (final Type type : genTypes) {
      if (type instanceof GeneratedTransferObject) { // searching for
        // ByteType
        final GeneratedTransferObject genTO = (GeneratedTransferObject) type;
        if (genTO.getName().equals("ByteType")) {
          byteTypeFound = true;
          List<GeneratedProperty> genProperties = genTO.getProperties();
          classPropertiesNumb = genProperties.size();

          genProperties = null;
          genProperties = genTO.getToStringIdentifiers();
          toStringPropertiesNum = genProperties.size();

          genProperties = null;
          genProperties = genTO.getEqualsIdentifiers();
          equalPropertiesNum = genProperties.size();

          genProperties = null;
          genProperties = genTO.getHashCodeIdentifiers();
          hashPropertiesNum = genProperties.size();
        }
      } else if (type instanceof GeneratedType) { // searching for
        // interface
        // LeafParameterContainer
        final GeneratedType genType = (GeneratedType) type;
        if (genType.getName().equals("LeafParentContainer")) {
          leafParentFound = true;
          // check of methods
          methodSignaturesList = genType.getMethodDefinitions();
          if (methodSignaturesList != null) {
            for (MethodSignature methodSignature : methodSignaturesList) { // loop
              // through
              // all
              // methods
              if (methodSignature.getName().equals("getByteLeaf")) {
                getByteLeafMethodFound = true;

                nameReturnParamType = methodSignature.getReturnType().getName();
              } else if (methodSignature.getName().equals("setByteLeaf")) {
                setByteLeafMethodFound = true;

                List<Parameter> parameters = methodSignature.getParameters();
                setByteLeafMethodParamNum = parameters.size();
              }
            }
          }
        }
      }
    }

    assertTrue(byteTypeFound);

    assertEquals(8, classPropertiesNumb);

    assertEquals(8, toStringPropertiesNum);
    assertEquals(8, equalPropertiesNum);
    assertEquals(8, hashPropertiesNum);
    assertTrue(leafParentFound);

    assertNotNull(methodSignaturesList);

    assertTrue(getByteLeafMethodFound);
    assertEquals("ByteType", nameReturnParamType);

    assertFalse(setByteLeafMethodFound);
    assertEquals(0, setByteLeafMethodParamNum);
  }
  @Test
  public void testInnerClassCreationForBitsAndUnionsInLeafes() throws URISyntaxException {
    final URI yangTypesPath = getClass().getResource("/bit_and_union_in_leaf.yang").toURI();

    final SchemaContext context = resolveSchemaContextFromFiles(yangTypesPath);
    assertTrue(context != null);

    final BindingGenerator bindingGen = new BindingGeneratorImpl();
    final List<Type> genTypes = bindingGen.generateTypes(context);
    assertTrue(genTypes != null);

    boolean parentContainerFound = false;
    boolean bitLeafTOFound = false;
    boolean unionLeafTOFound = false;

    boolean firstBitPropertyFound = false;
    boolean secondBitPropertyFound = false;
    boolean thirdBitPropertyFound = false;

    boolean firstBitPropertyTypeOK = false;
    boolean secondBitPropertyTypeOK = false;
    boolean thirdBitPropertyTypeOK = false;

    boolean int32UnionPropertyFound = false;
    boolean int32UnionPropertyTypeOK = false;
    boolean stringUnionPropertyFound = false;
    boolean stringUnionPropertyTypeOK = false;
    boolean uint8UnionPropertyFound = false;
    boolean uint8UnionPropertyTypeOK = false;

    for (Type type : genTypes) {
      if (type instanceof GeneratedType && !(type instanceof GeneratedTransferObject)) {
        if (type.getName().equals("ParentContainer")) {
          parentContainerFound = true;
          GeneratedType parentContainer = (GeneratedType) type;
          List<GeneratedType> enclosedTypes = parentContainer.getEnclosedTypes();
          for (GeneratedType genType : enclosedTypes) {
            if (genType instanceof GeneratedTransferObject) {
              if (genType.getName().equals("BitLeaf")) {
                bitLeafTOFound = true;
                GeneratedTransferObject bitLeafTO = (GeneratedTransferObject) genType;

                List<GeneratedProperty> bitLeafProperties = bitLeafTO.getProperties();
                for (GeneratedProperty bitLeafProperty : bitLeafProperties) {
                  String bitLeafPropertyType = bitLeafProperty.getReturnType().getName();
                  if (bitLeafProperty.getName().equals("firstBit")) {
                    firstBitPropertyFound = true;
                    if (bitLeafPropertyType.equals("Boolean")) {
                      firstBitPropertyTypeOK = true;
                    }
                  } else if (bitLeafProperty.getName().equals("secondBit")) {
                    secondBitPropertyFound = true;
                    if (bitLeafPropertyType.equals("Boolean")) {
                      secondBitPropertyTypeOK = true;
                    }
                  } else if (bitLeafProperty.getName().equals("thirdBit")) {
                    thirdBitPropertyFound = true;
                    if (bitLeafPropertyType.equals("Boolean")) {
                      thirdBitPropertyTypeOK = true;
                    }
                  }
                }

              } else if (genType.getName().equals("UnionLeaf")) {
                unionLeafTOFound = true;
                GeneratedTransferObject unionLeafTO = (GeneratedTransferObject) genType;

                List<GeneratedProperty> unionLeafProperties = unionLeafTO.getProperties();
                for (GeneratedProperty unionLeafProperty : unionLeafProperties) {
                  String unionLeafPropertyType = unionLeafProperty.getReturnType().getName();
                  if (unionLeafProperty.getName().equals("int32")) {
                    int32UnionPropertyFound = true;
                    if (unionLeafPropertyType.equals("Integer")) {
                      int32UnionPropertyTypeOK = true;
                    }
                  } else if (unionLeafProperty.getName().equals("string")) {
                    stringUnionPropertyFound = true;
                    if (unionLeafPropertyType.equals("String")) {
                      stringUnionPropertyTypeOK = true;
                    }
                  } else if (unionLeafProperty.getName().equals("uint8")) {
                    uint8UnionPropertyFound = true;
                    if (unionLeafPropertyType.equals("Short")) {
                      uint8UnionPropertyTypeOK = true;
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
    assertTrue(parentContainerFound);

    assertTrue(bitLeafTOFound);
    assertTrue(firstBitPropertyFound);
    assertTrue(secondBitPropertyFound);
    assertTrue(thirdBitPropertyFound);

    assertTrue(firstBitPropertyTypeOK);
    assertTrue(secondBitPropertyTypeOK);
    assertTrue(thirdBitPropertyTypeOK);

    assertTrue(unionLeafTOFound);
    assertTrue(int32UnionPropertyFound);
    assertTrue(int32UnionPropertyTypeOK);
    assertTrue(stringUnionPropertyFound);
    assertTrue(stringUnionPropertyTypeOK);
    assertTrue(uint8UnionPropertyFound);
    assertTrue(uint8UnionPropertyTypeOK);
  }