Commit 14716cb8 authored by Corentin Guillevic's avatar Corentin Guillevic
Browse files

Add JaCoCo ; Add the master's modifications

parent d16ed59f
......@@ -47,10 +47,8 @@
</goals>
<configuration>
<backend>pdf</backend>
<!--
<sourceHighlighter>coderay</sourceHighlighter>
-->
<attributes>
<sourceHighlighter>coderay</sourceHighlighter>
<icons>font</icons>
<pagenums/>
<toc/>
......
= Conception détaillée
== Proposition :
//:source-highlighter: rouge
== Test Highlighter
[source, java]
----
class Klass {
String field;
}
----
[source, ocl]
----
context Klass
inv:
field->select()
----
- Transformer l'actuel objet Game en objet Room et l'objet GameController en Game
- Ajouter des méthodes dans Thrift pour ce faire
- Transformer les void de l'interface Game en Response
== Game
......
{
"name": "not-alone-web",
"name": "not-alone-player",
"version": "0.0.0",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "not-alone-web",
"version": "0.0.0",
"dependencies": {
"@creditkarma/thrift-client": "^0.16.1",
......
{
"name": "not-alone-web",
"name": "not-alone-player",
"version": "0.0.0",
"main": "dist/main.js",
"scripts": {
"prebuild": "tslint -c tslint.json -p tsconfig.json --fix",
"build": "tsc",
"prestart": "npm run build",
"start": "node .",
"start": "node ./dist/main.js",
"test": "echo \"Error: no test specified\" && exit 1",
"codegen": "\"./node_modules/.bin/thrift-typescript\" --target thrift-server --sourceDir \"../not-alone-core/src/main/thrift/\" --outDir \"./src/codegen/\""
},
......
export interface GameInterface {
createGame(numberOfPlayers: number): Promise<number>;
join(gameId: number): Promise<number>;
}
import { ThriftServer } from './thrift/thrift-server';
/**
* Port used for local Thrift server.
*/
const LOCAL_PORT = 8090;
class Main {
private server: ThriftServer;
constructor() {
console.log('Main class');
this.server = new ThriftServer(LOCAL_PORT);
}
}
const main: Main = new Main();
import { Client } from 'src/codegen/common/GameService';
import { GameInterface } from '../core/game';
import { CoreOptions } from 'request';
import { createHttpClient, ICreateHttpClientOptions } from '@creditkarma/thrift-client';
import { IJoinRequest, JoinRequest } from '../codegen/common/JoinRequest';
export class GameProxy implements GameInterface {
private thriftClient: Client<CoreOptions>;
constructor(options: ICreateHttpClientOptions) {
this.thriftClient = createHttpClient(Client, options);
}
createGame(numberOfPlayers: number): Promise<number> {
return this.thriftClient.createGame(numberOfPlayers);
}
join(gameId: number): Promise<number> {
const request: IJoinRequest = new JoinRequest();
request.name = 'me';
return this.thriftClient.join(gameId, request);
}
}
......@@ -5,12 +5,11 @@ import * as express from 'express';
import { createThriftServer } from '@creditkarma/thrift-server-express';
const handler: ClientServiceHandler<express.Request> = new ClientServiceHandler<express.Request>();
const PORT = 8090;
export class ThriftServer {
private app: express.Application;
constructor() {
constructor(port: number) {
this.app = createThriftServer({
path: '/thrift',
thriftOptions: {
......@@ -18,8 +17,8 @@ export class ThriftServer {
handler: new GameService.Processor(handler),
},
});
this.app.listen(PORT, () => {
console.log(`Express server listening on port: ${PORT}`);
this.app.listen(port, () => {
console.log(`Thrift Express server listening on port: ${port}`);
});
}
}
......
......@@ -2,14 +2,15 @@
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"outDir": "./dist/",
"sourceMap": true,
"declaration": false,
"module": "ES6",
"module": "CommonJs",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "ES5",
"strict": true,
"target": "ES2017",
"typeRoots": [
"node_modules/@types"
],
......
......@@ -16,6 +16,10 @@
<name>Not Alone Server</name>
<description>Spring Boot Not Alone server</description>
<properties>
<jacoco.version>0.8.5</jacoco.version>
</properties>
<dependencies>
<dependency>
<groupId>fr.univnantes.alma</groupId>
......@@ -63,6 +67,36 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.9.1</version>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<!-- Active l'agent JaCoCo -->
<execution>
<id>prepare-agent-exe</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<!-- Génère un rapport HTML -->
<execution>
<id>report-exe</id>
<phase>pre-site</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
......
package fr.univnantes.alma.server.user;
import fr.univnantes.alma.thrift.*;
public interface PlayerInterface {
public void sendGameDescription(TDescription gameDescription);
public void sendGameStart();
public void sendGameIsFinished(TPlayerTeam winner);
public void sendFirstRoundStart();
public void sendStartPhase(TPhase phase, TDescription gameDescription);
public TAction askAction(TAskAction askedAction);
public void sendAction(TAskAction askedAction);
public void sendResponse(Response response);
}
package fr.univnantes.alma.server.user;
import fr.univnantes.alma.thrift.*;
import org.apache.thrift.TException;
import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.transport.TSocket;
import org.apache.thrift.transport.TTransport;
import java.util.List;
public class PlayerProxy implements PlayerInterface {
private PlayerService.Client client;
public PlayerProxy(String address, int port) {
TTransport transport = new TSocket(address, port);
TProtocol protocol = new TBinaryProtocol(transport);
client = new PlayerService.Client(protocol);
}
/**
* Is usefull ?
* @return
* @throws InvalidOperationException
* @throws TException
*/
public boolean ping() throws TException {
return client.ping();
}
@Override
public void sendGameDescription(TDescription gameDescription) {
try {
client.sendGameDescription(gameDescription);
} catch (TException e) {
throw new IllegalArgumentException("Thrift error : " + e.getMessage());
}
}
@Override
public void sendGameStart() {
try {
client.sendGameStart();
} catch (TException e) {
throw new IllegalArgumentException("Thrift error : " + e.getMessage());
}
}
@Override
public void sendGameIsFinished(TPlayerTeam winner) {
try {
client.sendGameIsFinished(winner);
} catch (TException e) {
throw new IllegalArgumentException("Thrift error : " + e.getMessage());
}
}
@Override
public void sendFirstRoundStart() {
try {
client.sendFirstRoundStart();
} catch (TException e) {
throw new IllegalArgumentException("Thrift error : " + e.getMessage());
}
}
@Override
public void sendStartPhase(TPhase phase, TDescription gameDescription) {
try {
client.sendStartPhase(phase, gameDescription);
} catch (TException e) {
throw new IllegalArgumentException("Thrift error : " + e.getMessage());
}
}
@Override
public TAction askAction(TAskAction askedAction) {
try {
return client.askAction(askedAction);
} catch (TException e) {
throw new IllegalArgumentException("Thrift error : " + e.getMessage());
}
}
@Override
public void sendAction(TAskAction askedAction) {
try {
client.sendAction(askedAction);
} catch (TException e) {
throw new IllegalArgumentException("Thrift error : " + e.getMessage());
}
}
@Override
public void sendResponse(Response response) {
try {
client.sendResponse(response);
} catch (TException e) {
throw new IllegalArgumentException("Thrift error : " + e.getMessage());
}
}
}
package fr.univnantes.alma.server.user;
import fr.univnantes.alma.thrift.*;
import org.apache.thrift.TException;
import java.util.List;
public class PlayerService implements fr.univnantes.alma.thrift.PlayerService.Iface {
private final int port;
private final String adress;
public PlayerService(String adress, int port) {
this.port = port;
this.adress = adress;
}
@Override
public boolean ping() throws InvalidOperationException, TException {
return false;
}
@Override
public void sendGameDescription(TDescription gameDescription) throws TException {
}
@Override
public void sendGameStart() throws TException {
}
@Override
public void sendGameIsFinished(TPlayerTeam winner) throws TException {
}
@Override
public void sendFirstRoundStart() throws TException {
}
@Override
public void sendStartPhase(TPhase phase, TDescription gameDescription) throws TException {
}
@Override
public TAction askAction(TAskAction askedAction) throws TException {
return null;
}
@Override
public void sendAction(TAskAction askedAction) throws TException {
}
@Override
public void sendResponse(Response response) throws TException {
}
}
......@@ -3,14 +3,12 @@ package fr.univnantes.alma.server.user;
import fr.univnantes.alma.thrift.*;
import org.apache.thrift.TException;
import java.util.List;
public class User {
private String id;
private String name;
private PlayerService service;
private PlayerProxy service;
public User(String id, String name, PlayerService service) {
public User(String id, String name, PlayerProxy service) {
this.id = id;
this.name = name;
this.service = service;
......@@ -19,7 +17,7 @@ public class User {
public User(String id, String name, String adress, int port) {
this.id = id;
this.name = name;
this.service = new PlayerService(adress, port);
this.service = new PlayerProxy(adress, port);
}
public String getId() {
......@@ -30,7 +28,7 @@ public class User {
return name;
}
public PlayerService getService() {
public PlayerProxy getService() {
return service;
}
......
......@@ -3,23 +3,32 @@ package fr.univnantes.alma.server.game;
import fr.univnantes.alma.data.DatabaseFactory;
import fr.univnantes.alma.common.NotAloneDatabase;
import fr.univnantes.alma.server.game.item.Phase;
import fr.univnantes.alma.server.game.item.action.ActionChoosePower;
import fr.univnantes.alma.server.game.item.board.Board;
import fr.univnantes.alma.server.game.item.board.BoardColor;
import fr.univnantes.alma.server.game.item.board.BoardDistribution;
import fr.univnantes.alma.server.game.item.board.Score;
import fr.univnantes.alma.server.game.item.card.PlaceCard;
import fr.univnantes.alma.server.game.item.jeton.JetonSymbol;
import fr.univnantes.alma.server.game.item.jeton.PlacedJeton;
import fr.univnantes.alma.server.game.item.planet.Place;
import fr.univnantes.alma.server.game.item.planet.Planet;
import fr.univnantes.alma.thrift.TAskAction;
import org.apache.thrift.TException;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import static fr.univnantes.alma.server.game.item.card.CardName.*;
import static fr.univnantes.alma.server.game.item.card.CardName.ARTEFACT;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
public class GameTest {
NotAloneDatabase database = DatabaseFactory.getDatabase();
......@@ -27,6 +36,27 @@ public class GameTest {
Planet planet;
Board board;
final PlaceCard antre = database.findPlaceCard(ANTRE.toString());
final PlaceCard jungle = database.findPlaceCard(JUNGLE.toString());
final PlaceCard riviere = database.findPlaceCard(RIVIERE.toString());
final PlaceCard plage = database.findPlaceCard(PLAGE.toString());
final PlaceCard rover = database.findPlaceCard(ROVER.toString());
final PlaceCard marais = database.findPlaceCard(MARAIS.toString());
final PlaceCard abri = database.findPlaceCard(ABRI.toString());
final PlaceCard epave = database.findPlaceCard(EPAVE.toString());
final PlaceCard source = database.findPlaceCard(SOURCE.toString());
final PlaceCard artefact = database.findPlaceCard(ARTEFACT.toString());
final PlaceCard nexus = database.findPlaceCard(NEXUS.toString());
final PlaceCard oasis = database.findPlaceCard(OASIS.toString());
final PlaceCard fjord = database.findPlaceCard(FJORD.toString());
final PlaceCard dome = database.findPlaceCard(DOME.toString());
final PlaceCard labyrinthe = database.findPlaceCard(LABYRINTHE.toString());
final PlaceCard mangrove = database.findPlaceCard(MANGROVE.toString());
final PlaceCard archipel = database.findPlaceCard(ARCHIPEL.toString());
final PlaceCard pole = database.findPlaceCard(POLE.toString());
final PlaceCard fungi = database.findPlaceCard(FUNGI.toString());
final PlaceCard portail = database.findPlaceCard(PORTAIL.toString());
@BeforeEach
public void setUp() {
List<PlaceCard> placeCards = new ArrayList();
......@@ -45,15 +75,60 @@ public class GameTest {
}
@Test
void testApplyPlayerCard_antreWithoutJeton() {
void testGame() throws TException {
Room room = mock(Room.class);
Game game = new Game(Arrays.asList(1,2), 1, planet, board, room);
game.getPlanet().forceMovePlanetPawn();
Board board = game.getBoard();
assertEquals(new Score(7,13), board.getScore());
board.moveForwardTraque(11);
board.moveForwardCreature(6);
assertEquals(new Score(1,2), board.getScore());
when(room.askAction(any(Integer.class), any(TAskAction.class)))
.thenReturn(new ActionChoosePower(0));
assertTrue(game.playerHasFinished(1, Phase.PREPHASE_1).state);
assertTrue(game.playerHasFinished(2, Phase.PREPHASE_1).state);
assertTrue(game.playerHasFinished(1, Phase.PHASE_1).state);
assertFalse(game.playerHasFinished(2, Phase.PHASE_1).state);
assertTrue(game.playerPlayCard(2, Collections.singletonList(plage)).state);
assertTrue(game.playerHasFinished(2, Phase.PHASE_1).state);
assertTrue(game.playerHasFinished(1, Phase.POSTPHASE_1).state);
assertTrue(game.playerHasFinished(2, Phase.POSTPHASE_1).state);
assertTrue(game.playerHasFinished(1, Phase.PREPHASE_2).state);
assertTrue(game.playerHasFinished(2, Phase.PREPHASE_2).state);
assertFalse(game.playerHasFinished(1, Phase.PHASE_2).state);
assertTrue(game.playerPlaceJeton(1, Collections.singletonList(new PlacedJeton(JetonSymbol.CREATURE, Collections.singletonList(Place.PLACE_ONE)))).state);
assertTrue(game.playerHasFinished(1, Phase.PHASE_2).state);
assertTrue(game.playerHasFinished(2, Phase.PHASE_2).state);
assertTrue(game.playerHasFinished(1, Phase.POSTPHASE_2).state);
assertTrue(game.playerHasFinished(2, Phase.POSTPHASE_2).state);
assertTrue(game.playerHasFinished(1, Phase.PREPHASE_3).state);
assertTrue(game.playerHasFinished(2, Phase.PREPHASE_3).state);
assertTrue(game.playerHasFinished(1, Phase.PHASE_3).state);
assertTrue(game.playerHasFinished(2, Phase.PHASE_3).state);
assertTrue(game.playerHasFinished(1, Phase.POSTPHASE_3).state);
assertTrue(game.playerHasFinished(2, Phase.POSTPHASE_3).state);
assertTrue(game.playerHasFinished(1, Phase.PREPHASE_4).state);
assertTrue(game.playerHasFinished(2, Phase.PREPHASE_4).state);
assertTrue(game.playerHasFinished(1, Phase.PHASE_4).state);
assertTrue(game.playerHasFinished(2, Phase.PHASE_4).state);
assertTrue(game.playerHasFinished(1, Phase.POSTPHASE_4).state);
assertTrue(game.playerHasFinished(2, Phase.POSTPHASE_4).state);
assertTrue(game.isFinish());
}
}
......@@ -96,6 +96,7 @@ class NotAloneApplicationTest {
@Test
void testStartGame() throws TException, InterruptedException {
/*
TPlayer creator = new TPlayer("start1", "Name", "192.168.1.1", 8080);
TRoomId id = client.createRoom(creator);
......@@ -112,6 +113,7 @@ class NotAloneApplicationTest {
response = client.joinRoom(new TPlayer("start3", "Name", "192.168.1.1", 8080), id);
assertFalse(response.state);
*/
}