Skip to content

Commit

Permalink
[sre][network] Add project for testing the network module of Janus.
Browse files Browse the repository at this point in the history
Signed-off-by: Stéphane Galland <galland@arakhne.org>
  • Loading branch information
gallandarakhneorg committed Mar 19, 2021
1 parent ec36924 commit 75aa86d
Show file tree
Hide file tree
Showing 14 changed files with 1,818 additions and 0 deletions.
120 changes: 120 additions & 0 deletions sre/io.janusproject/io.janusproject.network.tests/pom.xml
@@ -0,0 +1,120 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.janusproject.sre</groupId>
<artifactId>io.janusproject</artifactId>
<version>0.12.0-SNAPSHOT</version>
</parent>

<artifactId>io.janusproject.network.tests</artifactId>
<name>Janus Network Tests</name>

<dependencies>
<dependency>
<groupId>io.janusproject</groupId>
<artifactId>io.janusproject.kernel.network</artifactId>
</dependency>
<dependency>
<groupId>io.janusproject.sre</groupId>
<artifactId>io.janusproject.test.framework</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-test-source-folders</id>
<phase>initialize</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>src/test/sarl</source>
<source>src/test/generated-sources/sarl</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>io.sarl.maven</groupId>
<artifactId>sarl-maven-plugin</artifactId>
<!-- Maven extension mechanism seems not working because the plugin is
defined in the same project. The different goals must be explicitly provided. -->
<executions>
<execution>
<id>sarl-compiler-init</id>
<phase>initialize</phase>
<goals>
<goal>initialize</goal>
</goals>
</execution>
<execution>
<id>sarl-compiler-compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>sarl-compiler-testCompile</id>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
<execution>
<id>sarl-compiler-clean</id>
<phase>clean</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
<configuration>
<source>${sarl-dsl.min.jdk.version}</source>
<target>${sarl-dsl.min.jdk.version}</target>
<encoding>${project.build.sourceEncoding}</encoding>
<generateInlines>true</generateInlines>
<generateStorageFiles>false</generateStorageFiles>
<generateTraceFiles>false</generateTraceFiles>
</configuration>
</plugin>
<!-- The following plugin is needed to avoid the standard Java compilation before
the SARL compiler has generated the Java code. -->
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>default-compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<skip>true</skip>
</configuration>
</execution>
<execution>
<id>default-testCompile</id>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
<configuration>
<skip>true</skip>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,126 @@
/**
* $Id$
*
* SARL is an general-purpose agent programming language.
* More details on http://www.sarl.io
*
* Copyright (C) 2014-2021 the original authors or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.sarl.sre.network.tests.units.services;

import com.hazelcast.collection.ISet;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.map.IMap;
import io.sarl.lang.annotation.SarlElementType;
import io.sarl.lang.annotation.SarlSpecification;
import io.sarl.lang.annotation.SyntheticMember;
import io.sarl.sre.boot.configs.SreConfig;
import io.sarl.sre.boot.configs.subconfigs.BootConfig;
import io.sarl.sre.internal.Factories;
import io.sarl.sre.network.services.HazelcastContextService;
import io.sarl.sre.network.tests.units.services.mocks.IMapMock;
import io.sarl.sre.services.context.Context;
import io.sarl.sre.tests.framework.SreTestUtilities;
import io.sarl.sre.tests.framework.units.services.context.AbstractInjectionBasedContextServiceTest;
import io.sarl.tests.api.Nullable;
import java.util.UUID;
import javax.inject.Provider;
import org.eclipse.xtext.xbase.lib.Pure;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Tag;
import org.mockito.ArgumentMatchers;
import org.mockito.Mockito;

/**
* @author $Author: sgalland$
* @version $FullVersion$
* @mavengroupid $GroupId$
* @mavenartifactid $ArtifactId$
*/
@DisplayName("unit: HazelcastContextService test")
@Tag("unit")
@Tag("janus")
@Tag("sre-unit")
@Tag("sre-network")
@SarlSpecification("0.12")
@SarlElementType(10)
@SuppressWarnings("all")
public class HazelcastContextServiceTest extends AbstractInjectionBasedContextServiceTest<HazelcastContextService> {
@Nullable
private SreConfig sreConfig;

@Nullable
private HazelcastInstance hazelcast;

@SuppressWarnings("raw_type")
@Nullable
private ISet internalSet;

@Nullable
private IMap<UUID, UUID> istructure;

@BeforeEach
@Override
public void setUp() {
final UUID cid = UUID.randomUUID();
final UUID sid = UUID.randomUUID();
final BootConfig bootConfig = Mockito.<BootConfig>mock(BootConfig.class);
Mockito.<UUID>when(bootConfig.getRootContextID()).thenReturn(cid);
Mockito.<UUID>when(bootConfig.getRootSpaceID()).thenReturn(sid);
this.sreConfig = Mockito.<SreConfig>mock(SreConfig.class);
Mockito.<BootConfig>when(this.sreConfig.getBoot()).thenReturn(bootConfig);
IMapMock<UUID, UUID> _iMapMock = new IMapMock<UUID, UUID>();
this.istructure = _iMapMock;
this.internalSet = Mockito.<ISet>mock(ISet.class);
this.hazelcast = Mockito.<HazelcastInstance>mock(HazelcastInstance.class);
Mockito.<ISet<Object>>when(this.hazelcast.<Object>getSet(ArgumentMatchers.anyString())).thenReturn(this.internalSet);
Mockito.<IMap<UUID, UUID>>when(this.hazelcast.<UUID, UUID>getMap(ArgumentMatchers.anyString())).thenReturn(this.istructure);
super.setUp();
}

@Override
public HazelcastContextService newService(final Context rootContext) {
final Provider<Factories> _function = () -> {
return SreTestUtilities.newFactories();
};
return new HazelcastContextService(
this.sreConfig, rootContext,
this.loggingService,
this.injector,
this.contextFactory, _function,
this.hazelcast);
}

@Override
@Pure
@SyntheticMember
public boolean equals(final Object obj) {
return super.equals(obj);
}

@Override
@Pure
@SyntheticMember
public int hashCode() {
int result = super.hashCode();
return result;
}

@SyntheticMember
public HazelcastContextServiceTest() {
super();
}
}

0 comments on commit 75aa86d

Please sign in to comment.