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
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,9 @@ public List<JavaSource> generateAndCompile(final InputStream sourceStream) {
}
}

@Override
protected Injector getInjector() {
return injector;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,20 @@ package com.avaloq.tools.ddk.check.core.test

import com.avaloq.tools.ddk.check.CheckInjectorProvider
import java.io.ByteArrayInputStream
import org.eclipse.xtext.testing.InjectWith
import java.util.List
import org.eclipse.xtext.xbase.testing.JavaSource
import org.junit.jupiter.api.^extension.ExtendWith
import org.eclipse.xtext.testing.InjectWith
import org.eclipse.xtext.testing.extensions.InjectionExtension
import org.eclipse.xtext.xbase.testing.JavaSource
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.^extension.ExtendWith

import static org.junit.jupiter.api.Assertions.*

/**
* Unit test for autogeneration of check issue code to label map.
* Unit test for auto generation of check issue code to label map.
*/
@InjectWith(CheckInjectorProvider)
@ExtendWith(typeof(InjectionExtension))
@ExtendWith(InjectionExtension)
class IssueCodeToLabelMapGenerationTest extends AbstractCheckGenerationTestCase {

static final String PACKAGE_NAME = "mypackage"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*******************************************************************************
* 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.xtext.test.jupiter;

import static java.util.Collections.singleton;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IStorage;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.Path;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.xtext.resource.IResourceDescription;
import org.eclipse.xtext.resource.IResourceDescription.Delta;
import org.eclipse.xtext.ui.resource.IStorage2UriMapper;
import org.eclipse.xtext.ui.resource.Storage2UriMapperImpl;
import org.eclipse.xtext.util.Pair;
import org.eclipse.xtext.util.Tuples;


/**
* A base class for util test classes, which prepares common required mocks.
*/
@SuppressWarnings("nls")
public abstract class AbstractUtilTest extends AbstractXtextTest {

public static final String TEST_PROJECT_NAME = "TestProjectName";
private static final String DUMMY_PATH = TEST_PROJECT_NAME + "/TEST/";

// CHECKSTYLE:CHECK-OFF VisibilityModifierCheck
protected static Delta delta;
protected static IResourceDescription oldDesc;
protected static IResourceDescription newDesc;
protected static URI uriCorrect;
protected static Resource resource;
protected static IStorage2UriMapper mapperCorrect;
protected static IFile file;

// CHECKSTYLE:CHECK-ON VisibilityModifierCheck

/**
* Prepare mocks for all tests.
*/
public static void prepareMocksBase() {
oldDesc = mock(IResourceDescription.class);
newDesc = mock(IResourceDescription.class);
delta = mock(Delta.class);
resource = mock(Resource.class);
uriCorrect = mock(URI.class);
when(uriCorrect.isPlatformResource()).thenReturn(true);
when(uriCorrect.isFile()).thenReturn(true);
when(uriCorrect.toFileString()).thenReturn(DUMMY_PATH);
when(uriCorrect.toPlatformString(true)).thenReturn(DUMMY_PATH);
when(delta.getNew()).thenReturn(newDesc);
when(delta.getOld()).thenReturn(oldDesc);
when(delta.getUri()).thenReturn(uriCorrect);
when(resource.getURI()).thenReturn(uriCorrect);
file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(uriCorrect.toPlatformString(true)));
Iterable<Pair<IStorage, IProject>> storages = singleton(Tuples.<IStorage, IProject> create(file, file.getProject()));
mapperCorrect = mock(Storage2UriMapperImpl.class);
when(mapperCorrect.getStorages(uriCorrect)).thenReturn(storages);
}

}
4 changes: 3 additions & 1 deletion com.avaloq.tools.ddk.xtext.test/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ Require-Bundle: com.avaloq.tools.ddk.xtext,
junit-jupiter-api,
junit-jupiter-engine,
junit-vintage-engine,
junit-platform-suite-api
junit-platform-suite-api,
org.eclipse.xtext.testing,
org.opentest4j
Import-Package: org.slf4j, org.apache.log4j,
com.avaloq.tools.ddk.check.runtime.test.core,
com.avaloq.tools.ddk.check.test.core,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,27 @@
*******************************************************************************/
package com.avaloq.tools.ddk.xtext;

import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.platform.suite.api.SelectClasses;
import org.junit.platform.suite.api.Suite;

import com.avaloq.tools.ddk.xtext.builder.XtextBuildTriggerTest;
import com.avaloq.tools.ddk.xtext.formatter.FormatterTest;
import com.avaloq.tools.ddk.xtext.jupiter.formatter.FormatterTest;
import com.avaloq.tools.ddk.xtext.linking.AbstractFragmentProviderTest;
import com.avaloq.tools.ddk.xtext.linking.ShortFragmentProviderTest;
import com.avaloq.tools.ddk.xtext.naming.QualifiedNamePatternTest;
import com.avaloq.tools.ddk.xtext.naming.QualifiedNameSegmentTreeLookupTest;
import com.avaloq.tools.ddk.xtext.resource.AbstractSelectorFragmentProviderTest;
import com.avaloq.tools.ddk.xtext.resource.ResourceDescriptionDeltaTest;
import com.avaloq.tools.ddk.xtext.resource.BugAig1084;
import com.avaloq.tools.ddk.xtext.resource.ResourceDescriptionDeltaTest;
import com.avaloq.tools.ddk.xtext.util.RuntimeProjectUtilTest;


/**
* Empty class serving only as holder for JUnit4 annotations.
* Empty class serving only as holder for JUnit5 annotations.
*/
// @Format-Off
@RunWith(Suite.class)
@Suite.SuiteClasses({
@Suite
@SelectClasses({
AbstractFragmentProviderTest.class,
ShortFragmentProviderTest.class,
AbstractSelectorFragmentProviderTest.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,39 +24,38 @@
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.xtext.builder.impl.BuildScheduler;
import org.eclipse.xtext.builder.impl.IBuildFlag;
import org.eclipse.xtext.testing.AbstractXtextTests;
import org.junit.Before;
import org.junit.Test;
import org.eclipse.xtext.testing.InjectWith;
import org.eclipse.xtext.testing.extensions.InjectionExtension;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentMatchers;

import com.avaloq.tools.ddk.xtext.builder.layered.XtextBuildTrigger;
import com.google.inject.AbstractModule;
import com.google.inject.Inject;
import com.google.inject.Injector;


@SuppressWarnings({"restriction", "deprecation", "removal"})
public class XtextBuildTriggerTest extends AbstractXtextTests {
@SuppressWarnings({"restriction", "deprecation"})
@InjectWith(XtextBuilderInjectorProvider.class)
@ExtendWith(InjectionExtension.class)
public class XtextBuildTriggerTest {

@Inject
private Injector injector;

private IWorkspace workspace;
private BuildScheduler scheduler;

@Override
@Before
public void setUp() throws Exception {
super.setUp();
workspace = mock(IWorkspace.class);
scheduler = mock(BuildScheduler.class);
with(new AbstractModule() {
@Override
protected void configure() {
bind(BuildScheduler.class).toInstance(scheduler);
bind(IWorkspace.class).toInstance(workspace);
}
});
@BeforeEach
public void setUp() {
workspace = injector.getInstance(IWorkspace.class);
scheduler = injector.getInstance(BuildScheduler.class);
}

@Test
public void testTriggerRespectsAutoBuilding() {
XtextBuildTrigger buildTrigger = get(XtextBuildTrigger.class);
XtextBuildTrigger buildTrigger = injector.getInstance(XtextBuildTrigger.class);

// auto-build disabled
when(workspace.isAutoBuilding()).thenReturn(false);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*******************************************************************************
* Copyright (c) 2016 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 Evolution AG - initial API and implementation
*******************************************************************************/

package com.avaloq.tools.ddk.xtext.builder;

import static org.mockito.Mockito.mock;

import org.eclipse.core.resources.IWorkspace;
import org.eclipse.xtext.builder.impl.BuildScheduler;
import org.eclipse.xtext.testing.IInjectorProvider;

import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;


public class XtextBuilderInjectorProvider implements IInjectorProvider {

@Override
public Injector getInjector() {
return Guice.createInjector(new AbstractModule() {
@SuppressWarnings({"deprecation", "restriction"})
@Override
protected void configure() {
bind(BuildScheduler.class).toInstance(mock(BuildScheduler.class));
bind(IWorkspace.class).toInstance(mock(IWorkspace.class));
}
});
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*******************************************************************************
* 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.xtext.jupiter.formatter;

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.io.IOException;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtext.formatting.INodeModelFormatter;
import org.eclipse.xtext.formatting.INodeModelFormatter.IFormattedRegion;
import org.eclipse.xtext.nodemodel.ICompositeNode;
import org.eclipse.xtext.nodemodel.util.NodeModelUtils;
import org.eclipse.xtext.resource.SaveOptions;
import org.eclipse.xtext.serializer.ISerializer;

import com.avaloq.tools.ddk.xtext.test.jupiter.AbstractXtextTest;


/**
* Base class for formatting tests.
* The assertXyz methods are essentially copied from {@link com.avaloq.tools.ddk.xtext.test.formatting.AbstractAcfFormattingTest}.
*/
@SuppressWarnings("nls")
public abstract class AbstractFormatterTest extends AbstractXtextTest {

/**
* Loads a model from a string representation of a source.
*
* @param input
* String representing a serialized model
* @return Loaded model
*/
private EObject getModel(final String input) throws IOException {
return getXtextTestUtil().getModel("mytestmodel." + getXtextTestUtil().getFileExtension(), input);
}

/**
* Gets the Guice injected serializer.
*
* @return Serializer the DI serializer
*/
protected ISerializer getSerializer() {
return getXtextTestUtil().getSerializer();
}

// test formatting based on the ParseTreeConstructorin
protected void assertFormattedPTC(final String expected, final String model) throws IOException {
EObject m = getModel(model);
String res = getSerializer().serialize(m, SaveOptions.newBuilder().format().getOptions());
assertEquals(expected, res, "Serialization not equal");
}

protected void assertPreserved(final String model) throws IOException {
EObject m = getModel(model);
String res = getSerializer().serialize(m, SaveOptions.newBuilder().getOptions());
assertEquals(model, res, "Preserved node model");
}

// test formatting based on the NodeModel
protected void assertFormattedNM(final String expected, final String model, final int offset, final int length) throws IOException {
ICompositeNode node = NodeModelUtils.getNode(getModel(model)).getRootNode();
IFormattedRegion r = getXtextTestUtil().get(INodeModelFormatter.class).format(node, offset, length);
String actual = model.substring(0, r.getOffset()) + r.getFormattedText() + model.substring(r.getLength() + r.getOffset());
assertEquals(expected, actual, "Formatting based on the NodeModel");
}

}
Loading