Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion com.avaloq.tools.ddk.test.core/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ Require-Bundle: org.eclipse.core.runtime,
com.google.guava,
org.apache.commons.lang,
org.eclipse.emf.common,
com.avaloq.tools.ddk
com.avaloq.tools.ddk,
junit-jupiter-api
Export-Package: com.avaloq.tools.ddk.test.core,
com.avaloq.tools.ddk.test.core.data,
com.avaloq.tools.ddk.test.core.junit.runners,
com.avaloq.tools.ddk.test.core.jupiter,
com.avaloq.tools.ddk.test.core.mock,
com.avaloq.tools.ddk.test.core.util
Import-Package: org.apache.logging.log4j
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*******************************************************************************
* Copyright (c) 2025 Avaloq Group AG and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Avaloq Group AG - initial API and implementation
*******************************************************************************/
package com.avaloq.tools.ddk.test.core.jupiter;

import java.lang.reflect.Method;

import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.api.extension.InvocationInterceptor;
import org.junit.jupiter.api.extension.ReflectiveInvocationContext;

import com.avaloq.tools.ddk.test.core.BugTest;


/**
* This {@link InvocationInterceptor} implementation changes the behavior for unresolved bug tests.
* <p>
* The behavior for at test that is annotated with {@link BugTest(unresolved=true)} is the following:
* <ul>
* <li>Test evaluation <code>OK</code> results in <code>FAIL</code> ({@link AssertionError})</li>
* <li>Test evaluation <code>FAIL</code> results in <code>OK</code></li>
* <li>Test evaluation <code>ERROR</code> results in <code>ERROR</code></li>
* </ul>
* </p>
* <p>
* Example for a bug test:
*
* <pre>
* public class TestClass {
*
* &#064;Rule
* public BugTestAwareRule rule = BugTestAwareRule.getInstance();
*
* &#064;org.junit.Test
* &#064;com.avaloq.tools.ddk.test.core.BugTest(value = &quot;BUG-42&quot;, unresolved = true)
* public void testMethod() {
* org.junit.Assert.fail();
* }
* }
* </pre>
* </p>
*
* @see BugTest
*/
public final class BugTestAwareRule implements InvocationInterceptor {

private static final String ERROR_TEST_MUST_FAIL = "The unresolved bug test must fail:"; //$NON-NLS-1$
/** The singleton instance, or {@code null} if not cached. */
private static BugTestAwareRule instance;
private static final Object LOCK = new Object();

/**
* Creates a new instance of {@link BugTestAwareRule}.
*/
private BugTestAwareRule() {
// prevent instantiation
}

/**
* Returns a shared singleton instance.
*
* @return a shared instance, never {@code null}
*/
public static BugTestAwareRule getInstance() {
synchronized (LOCK) {
if (instance == null) {
instance = new BugTestAwareRule();
}
return instance;
}
}

@SuppressWarnings("nls")
@Override
public void interceptTestMethod(final Invocation<Void> invocation, final ReflectiveInvocationContext<Method> invocationContext, final ExtensionContext extensionContext) throws Throwable {
BugTest bugTestAnnotation = extensionContext.getRequiredTestMethod().getAnnotation(BugTest.class);
if (bugTestAnnotation == null && extensionContext.getRequiredTestClass() != null) {
bugTestAnnotation = extensionContext.getRequiredTestClass().getAnnotation(BugTest.class);
}
if (bugTestAnnotation != null && bugTestAnnotation.unresolved()) {
try {
invocation.proceed();
} catch (AssertionError exception) {
return;
}
String testCase = extensionContext.getRequiredTestClass().getSimpleName() + "." + extensionContext.getRequiredTestMethod().getName();
throw new AssertionError(ERROR_TEST_MUST_FAIL + " " + testCase);
} else {
invocation.proceed();
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*******************************************************************************
* Copyright (c) 2025 Avaloq Group AG and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Avaloq Group AG - initial API and implementation
*******************************************************************************/
package com.avaloq.tools.ddk.test.core.jupiter;

import java.lang.reflect.Method;

import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.api.extension.InvocationInterceptor;
import org.junit.jupiter.api.extension.ReflectiveInvocationContext;

import com.avaloq.tools.ddk.test.core.Issue;


/**
* This {@link InvocationInterceptor} implementation changes the behavior for not fixed issues.
* <p>
* The behavior for at test that is annotated with {@link Issue(fixed = false)} is the following:
* <ul>
* <li>Test evaluation <code>OK</code> results in <code>FAIL</code> ({@link AssertionError})</li>
* <li>Test evaluation <code>FAIL</code> results in <code>OK</code></li>
* <li>Test evaluation <code>ERROR</code> results in <code>ERROR</code></li>
* </ul>
* </p>
* <p>
* Example for a issue test:
*
* <pre>
* public class TestClass {
*
* &#064;Rule
* public IssueAwareRule rule = IssueAwareRule.getInstance();
*
* &#064;org.junit.Test
* &#064;com.avaloq.tools.ddk.test.core.Issue(value = &quot;ISSUE-42&quot;, fixed = false)
* public void testMethod() {
* org.junit.Assert.fail();
* }
* }
* </pre>
* </p>
*
* @see Issue
*/
public final class IssueAwareRule implements InvocationInterceptor {

private static final String ERROR_TEST_MUST_FAIL = "The issue test for a not fixed issue must fail:"; //$NON-NLS-1$
/** The singleton instance, or {@code null} if not cached. */
private static IssueAwareRule instance;
private static Object lock = new Object();

/**
* Creates a new instance of {@link IssueAwareRule}.
*/
private IssueAwareRule() {
// prevent instantiation
}

/**
* Returns a shared singleton instance.
*
* @return a shared instance, never {@code null}
*/
public static IssueAwareRule getInstance() {
synchronized (lock) {
if (instance == null) {
instance = new IssueAwareRule();
}
return instance;
}
}

@SuppressWarnings("nls")
@Override
public void interceptTestMethod(final Invocation<Void> invocation, final ReflectiveInvocationContext<Method> invocationContext, final ExtensionContext extensionContext) throws Throwable {
Issue issueAnnotation = extensionContext.getRequiredTestMethod().getAnnotation(Issue.class);
if (issueAnnotation == null && extensionContext.getRequiredTestClass() != null) {
issueAnnotation = extensionContext.getRequiredTestClass().getAnnotation(Issue.class);
}
if (issueAnnotation != null && issueAnnotation.fixed()) {
try {
invocation.proceed();
} catch (AssertionError exception) {
return;
}
String testCase = extensionContext.getRequiredTestClass().getSimpleName() + "." + extensionContext.getRequiredTestMethod().getName();
throw new AssertionError(ERROR_TEST_MUST_FAIL + " " + testCase);
} else {
invocation.proceed();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*******************************************************************************
* Copyright (c) 2025 Avaloq Group AG and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Avaloq Group AG - initial API and implementation
*******************************************************************************/
package com.avaloq.tools.ddk.test.core.jupiter;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.jupiter.api.extension.AfterEachCallback;
import org.junit.jupiter.api.extension.BeforeEachCallback;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.api.extension.TestWatcher;


/**
* A test watcher that logs the start and end of each test, as well as its success or failure.
*/
@SuppressWarnings("nls")
public final class LoggingRule implements TestWatcher, BeforeEachCallback, AfterEachCallback {

private static final Logger LOGGER = LogManager.getLogger(LoggingRule.class);

/** The singleton instance, or {@code null} if not cached. */
private static LoggingRule instance;

private static final Object LOCK = new Object();

/**
* Creates a new instance of {@link LoggingRule}.
*/
private LoggingRule() {
// prevent instantiation
}

/**
* Returns a shared singleton instance.
*
* @return a shared instance, never {@code null}
*/
public static LoggingRule getInstance() {
synchronized (LOCK) {
if (instance == null) {
instance = new LoggingRule();
}
return instance;
}
}

@Override
public void beforeEach(final ExtensionContext context) throws Exception {
if (LOGGER.isInfoEnabled()) {
LOGGER.info("STARTING: " + getDescriptionName(context));
}
}

/**
* Returns the name of a test to be logged.
*
* @param description
* the description, must not be {@code null}
* @return the description name, never {@code null}
*/
private String getDescriptionName(final ExtensionContext context) {
return context.getRequiredTestClass().getSimpleName() + '.' + context.getRequiredTestMethod().getName();
}

@Override
public void testSuccessful(final ExtensionContext context) {
if (LOGGER.isInfoEnabled()) {
LOGGER.info("SUCCEEDED: " + getDescriptionName(context));
}
}

@Override
public void testFailed(final ExtensionContext context, final Throwable cause) {
if (LOGGER.isInfoEnabled()) {
LOGGER.info("FAILED: " + getDescriptionName(context));
}
}

@Override
public void afterEach(final ExtensionContext context) throws Exception {
if (LOGGER.isInfoEnabled()) {
LOGGER.info("FINISHED: " + getDescriptionName(context));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,18 @@ Bundle-Vendor: Avaloq Group AG
Bundle-RequiredExecutionEnvironment: JavaSE-21
Bundle-ActivationPolicy: lazy
Fragment-Host: com.avaloq.tools.ddk.xtext.generator
Require-Bundle: com.avaloq.tools.ddk.test.core,
Require-Bundle: com.avaloq.tools.ddk.test.core,
com.avaloq.tools.ddk.xtext.expression,
com.avaloq.tools.ddk.xtext.test.core,
org.eclipse.xtend,
org.eclipse.xtend.typesystem.emf,
org.eclipse.xtext,
org.junit,
org.mockito.mockito-core,
com.avaloq.tools.ddk.xtext.ui,
org.eclipse.xtext.xtext.generator,
junit-jupiter-api,
junit-jupiter-engine,
junit-vintage-engine
junit-platform-suite-api
Export-Package: com.avaloq.tools.ddk.xtext.generator.test.generator
Import-Package: org.eclipse.xtext.ui.resource
Automatic-Module-Name: com.avaloq.tools.ddk.xtext.generator.test
Loading