Esempio n. 1
0
  @Override
  public void setUp() throws Exception {
    super.setUp();

    pkg = EMFUtil.createEPackage("customTest", "ct", "http://cdo.emf.eclipse.org/customTest.ecore");
    EDataType custom = EcoreFactory.eINSTANCE.createEDataType();
    custom.setInstanceClass(CustomType.class);
    custom.setName("CustomType");

    pkg.getEClassifiers().add(custom);

    cls = EMFUtil.createEClass(pkg, "Foobar", false, false);
    att = EMFUtil.createEAttribute(cls, "att", custom);

    CDOUtil.prepareDynamicEPackage(pkg);
  }
Esempio n. 2
0
  /**
   * Constructs a test-specific EPackage of the format "pkg123_name". Using this instead of (just) a
   * hardcoded name for the test package, ensures that the test method is isolated from all others.
   *
   * @param name the test-local name of the package or <code>null</code> .
   * @return the created package.
   * @see #createUniquePackage()
   */
  public final EPackage createUniquePackage(String name) {
    if (dynamicPackageNumber == 0) {
      dynamicPackageNumber = ++dynamicPackageCounter;
    }

    StringBuilder builder = new StringBuilder();
    builder.append("pkg");
    builder.append(dynamicPackageNumber);

    if (name != null) {
      builder.append('_');
      builder.append(name);
    }

    final String uniqueName = builder.toString();

    EPackage ePackage = EMFUtil.createEPackage(uniqueName, uniqueName, "http://" + uniqueName);
    ePackage
        .eAdapters()
        .add(
            new AdapterImpl() {
              @Override
              public void notifyChanged(Notification msg) {
                if (msg.isTouch()) {
                  return;
                }

                Object feature = msg.getFeature();
                if (feature == EcorePackage.Literals.EPACKAGE__NS_PREFIX
                    || feature == EcorePackage.Literals.EPACKAGE__NS_URI
                    || feature == EcorePackage.Literals.ENAMED_ELEMENT__NAME) {
                  throw new ImplementationError("Don't change the unique package " + uniqueName);
                }
              }
            });

    return ePackage;
  }