protected void showAnnotationPanel(String annoText) {
    String text = this.splitLines(annoText);

    AnnotationAttributes attrs = this.getAnnotationPanelAttributes(text);
    int yOffset =
        Math.min(this.controller.getWWPanel().getSize().height - attrs.getSize().height, 250);
    Point location = new Point(10 + attrs.getSize().width / 2, yOffset);

    if (this.annotationPanel != null)
      this.annotationPanel.setAttributes(this.getAnnotationPanelAttributes(text));
    else
      this.annotationPanel =
          new ScreenAnnotation(annoText, location, getAnnotationPanelAttributes(text));

    this.annotationPanel.setScreenPoint(location);
    this.annotationPanel.setText(text);

    if (this.annotationLayer == null) {
      this.annotationLayer = new AnnotationLayer();
      this.annotationLayer.setPickEnabled(false);
    }

    this.annotationLayer.removeAllAnnotations();
    this.annotationLayer.addAnnotation(this.annotationPanel);
    if (!this.controller.getActiveLayers().contains(this.annotationLayer))
      this.controller.addInternalLayer(this.annotationLayer);
  }
Пример #2
0
 private void setupOrTeardown(
     DbUnitTestContext testContext, boolean isSetup, Collection<AnnotationAttributes> annotations)
     throws Exception {
   IDatabaseConnection connection = testContext.getConnection();
   DatabaseOperation lastOperation = null;
   for (AnnotationAttributes annotation : annotations) {
     for (String dataSetLocation : annotation.getValue()) {
       DatabaseOperation operation = annotation.getType();
       org.dbunit.operation.DatabaseOperation dbUnitDatabaseOperation =
           getDbUnitDatabaseOperation(testContext, operation, lastOperation);
       IDataSet dataSet = loadDataset(testContext, dataSetLocation);
       if (dataSet != null) {
         if (logger.isDebugEnabled()) {
           logger.debug(
               "Executing "
                   + (isSetup ? "Setup" : "Teardown")
                   + " of @DatabaseTest using "
                   + operation
                   + " on "
                   + dataSetLocation);
         }
         dbUnitDatabaseOperation.execute(connection, dataSet);
         lastOperation = operation;
       }
     }
   }
 }
  private AnnotationAttributes assertComponentScanAttributes(Class<?> element, String... expected) {
    AnnotationAttributes attributes = findMergedAnnotationAttributes(element, ComponentScan.class);

    assertNotNull("Should find @ComponentScan on " + element, attributes);
    assertArrayEquals("value: ", expected, attributes.getStringArray("value"));
    assertArrayEquals("basePackages: ", expected, attributes.getStringArray("basePackages"));

    return attributes;
  }
 @Test
 public void findMergedAnnotationAttributesOnClassWithMetaAndLocalTxConfig() {
   AnnotationAttributes attributes =
       findMergedAnnotationAttributes(MetaAndLocalTxConfigClass.class, Transactional.class);
   assertNotNull("Should find @Transactional on MetaAndLocalTxConfigClass", attributes);
   assertEquals(
       "TX qualifier for MetaAndLocalTxConfigClass.",
       "localTxMgr",
       attributes.getString("qualifier"));
 }
 @Test
 public void getMergedAnnotationAttributesOnClassWithLocalAnnotation() {
   Class<?> element = TxConfig.class;
   String name = TX_NAME;
   AnnotationAttributes attributes = getMergedAnnotationAttributes(element, name);
   assertNotNull("Annotation attributes for @Transactional on TxConfig", attributes);
   assertEquals("value for TxConfig.", "TxConfig", attributes.getString("value"));
   // Verify contracts between utility methods:
   assertTrue(isAnnotated(element, name));
 }
  @Test
  public void
      findMergedAnnotationAttributesOnClassWithAttributeAliasInComposedAnnotationAndNestedAnnotationsInTargetAnnotation() {
    AnnotationAttributes attributes =
        assertComponentScanAttributes(TestComponentScanClass.class, "com.example.app.test");

    Filter[] excludeFilters = attributes.getAnnotationArray("excludeFilters", Filter.class);
    assertNotNull(excludeFilters);

    List<String> patterns = stream(excludeFilters).map(Filter::pattern).collect(toList());
    assertEquals(asList("*Test", "*Tests"), patterns);
  }
 @Test
 public void getMergedAnnotationAttributesFavorsLocalComposedAnnotationOverInheritedAnnotation() {
   Class<?> element = SubClassWithInheritedAnnotation.class;
   String name = TX_NAME;
   AnnotationAttributes attributes = getMergedAnnotationAttributes(element, name);
   assertNotNull(
       "AnnotationAttributes for @Transactional on SubClassWithInheritedAnnotation", attributes);
   // Verify contracts between utility methods:
   assertTrue(isAnnotated(element, name));
   assertTrue(
       "readOnly flag for SubClassWithInheritedAnnotation.", attributes.getBoolean("readOnly"));
 }
  @Test
  public void getMergedAnnotationAttributesWithAliasedValueComposedAnnotation() {
    Class<?> element = AliasedValueComposedContextConfigClass.class;
    String name = ContextConfig.class.getName();
    AnnotationAttributes attributes = getMergedAnnotationAttributes(element, name);

    assertNotNull("Should find @ContextConfig on " + element.getSimpleName(), attributes);
    assertArrayEquals("locations", asArray("test.xml"), attributes.getStringArray("locations"));
    assertArrayEquals("value", asArray("test.xml"), attributes.getStringArray("value"));

    // Verify contracts between utility methods:
    assertTrue(isAnnotated(element, name));
  }
  @Test
  public void
      getMergedAnnotationAttributesWithImplicitAliasesInMetaAnnotationOnComposedAnnotation() {
    Class<?> element = ComposedImplicitAliasesContextConfigClass.class;
    String name = ImplicitAliasesContextConfig.class.getName();
    AnnotationAttributes attributes = getMergedAnnotationAttributes(element, name);
    String[] expected = asArray("A.xml", "B.xml");

    assertNotNull(
        "Should find @ImplicitAliasesContextConfig on " + element.getSimpleName(), attributes);
    assertArrayEquals("groovyScripts", expected, attributes.getStringArray("groovyScripts"));
    assertArrayEquals("xmlFiles", expected, attributes.getStringArray("xmlFiles"));
    assertArrayEquals("locations", expected, attributes.getStringArray("locations"));
    assertArrayEquals("value", expected, attributes.getStringArray("value"));

    // Verify contracts between utility methods:
    assertTrue(isAnnotated(element, name));
  }
  private void getMergedAnnotationAttributesWithHalfConventionBasedAndHalfAliasedComposedAnnotation(
      Class<?> clazz) {
    String[] expected = asArray("explicitDeclaration");
    String name = ContextConfig.class.getName();
    String simpleName = clazz.getSimpleName();
    AnnotationAttributes attributes = getMergedAnnotationAttributes(clazz, name);

    assertNotNull("Should find @ContextConfig on " + simpleName, attributes);
    assertArrayEquals(
        "locations for class [" + clazz.getSimpleName() + "]",
        expected,
        attributes.getStringArray("locations"));
    assertArrayEquals(
        "value for class [" + clazz.getSimpleName() + "]",
        expected,
        attributes.getStringArray("value"));

    // Verify contracts between utility methods:
    assertTrue(isAnnotated(clazz, name));
  }
  @Test
  public void findAndSynthesizeAnnotationAttributesOnClassWithAttributeAliasesInTargetAnnotation() {
    String qualifier = "aliasForQualifier";

    // 1) Find and merge AnnotationAttributes from the annotation hierarchy
    AnnotationAttributes attributes =
        findMergedAnnotationAttributes(
            AliasedTransactionalComponentClass.class, AliasedTransactional.class);
    assertNotNull("@AliasedTransactional on AliasedTransactionalComponentClass.", attributes);

    // 2) Synthesize the AnnotationAttributes back into the target annotation
    AliasedTransactional annotation =
        AnnotationUtils.synthesizeAnnotation(
            attributes, AliasedTransactional.class, AliasedTransactionalComponentClass.class);
    assertNotNull(annotation);

    // 3) Verify that the AnnotationAttributes and synthesized annotation are equivalent
    assertEquals("TX value via attributes.", qualifier, attributes.getString("value"));
    assertEquals("TX value via synthesized annotation.", qualifier, annotation.value());
    assertEquals("TX qualifier via attributes.", qualifier, attributes.getString("qualifier"));
    assertEquals("TX qualifier via synthesized annotation.", qualifier, annotation.qualifier());
  }
Пример #12
0
 /**
  * Called after a test method is executed to perform any database teardown and to check expected
  * results.
  *
  * @param testContext The test context
  * @throws Exception
  */
 public void afterTestMethod(DbUnitTestContext testContext) throws Exception {
   try {
     verifyExpected(testContext, getAnnotations(testContext, ExpectedDatabase.class));
     Collection<DatabaseTearDown> annotations =
         getAnnotations(testContext, DatabaseTearDown.class);
     try {
       setupOrTeardown(testContext, false, AnnotationAttributes.get(annotations));
     } catch (RuntimeException e) {
       if (testContext.getTestException() == null) {
         throw e;
       }
       if (logger.isWarnEnabled()) {
         logger.warn("Unable to throw database cleanup exception due to existing test error", e);
       }
     }
   } finally {
     testContext.getConnection().close();
   }
 }
Пример #13
0
  protected void setupAnnotationAttributes(Annotation annotation) {
    java.awt.Color transparentBlack = new java.awt.Color(0, 0, 0, 0);

    AnnotationAttributes defaultAttribs = new AnnotationAttributes();
    defaultAttribs.setAdjustWidthToText(AVKey.SIZE_FIXED);
    defaultAttribs.setBackgroundColor(transparentBlack);
    defaultAttribs.setBorderColor(transparentBlack);
    defaultAttribs.setBorderWidth(0);
    defaultAttribs.setCornerRadius(0);
    defaultAttribs.setDrawOffset(new java.awt.Point(0, 0));
    defaultAttribs.setHighlightScale(1);
    defaultAttribs.setInsets(new java.awt.Insets(0, 0, 0, 0));
    defaultAttribs.setImageScale(1);
    defaultAttribs.setImageOffset(new java.awt.Point(0, 0));
    defaultAttribs.setImageOpacity(1);
    defaultAttribs.setImageRepeat(AVKey.REPEAT_NONE);
    defaultAttribs.setLeader(AVKey.SHAPE_NONE);
    defaultAttribs.setSize(new java.awt.Dimension(0, 0));

    annotation.setPickEnabled(false);
    annotation.getAttributes().setDefaults(defaultAttribs);
  }
  protected AnnotationAttributes getAnnotationPanelAttributes(String annoText) {
    AnnotationAttributes attrs = new AnnotationAttributes();

    attrs.setAdjustWidthToText(AVKey.SIZE_FIXED);
    attrs.setSize(this.computePanelSize(annoText));
    attrs.setFrameShape(AVKey.SHAPE_RECTANGLE);
    attrs.setTextColor(Color.WHITE);
    attrs.setBackgroundColor(new Color(0f, 0f, 0f, 0.6f));
    attrs.setCornerRadius(10);
    attrs.setInsets(new Insets(10, 10, 0, 0));
    attrs.setBorderColor(new Color(0xababab));
    attrs.setFont(Font.decode("Arial-PLAIN-12"));
    attrs.setTextAlign(AVKey.LEFT);

    return attrs;
  }
Пример #15
0
 /**
  * Called before a test method is executed to perform any database setup.
  *
  * @param testContext The test context
  * @throws Exception
  */
 public void beforeTestMethod(DbUnitTestContext testContext) throws Exception {
   Collection<DatabaseSetup> annotations = getAnnotations(testContext, DatabaseSetup.class);
   setupOrTeardown(testContext, true, AnnotationAttributes.get(annotations));
 }