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 @@ ...@@ -47,10 +47,8 @@
</goals> </goals>
<configuration> <configuration>
<backend>pdf</backend> <backend>pdf</backend>
<!--
<sourceHighlighter>coderay</sourceHighlighter>
-->
<attributes> <attributes>
<sourceHighlighter>coderay</sourceHighlighter>
<icons>font</icons> <icons>font</icons>
<pagenums/> <pagenums/>
<toc/> <toc/>
......
= Conception détaillée = 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 == Game
......
{ {
"name": "not-alone-web", "name": "not-alone-player",
"version": "0.0.0", "version": "0.0.0",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "not-alone-web",
"version": "0.0.0", "version": "0.0.0",
"dependencies": { "dependencies": {
"@creditkarma/thrift-client": "^0.16.1", "@creditkarma/thrift-client": "^0.16.1",
......
{ {
"name": "not-alone-web", "name": "not-alone-player",
"version": "0.0.0", "version": "0.0.0",
"main": "dist/main.js",
"scripts": { "scripts": {
"prebuild": "tslint -c tslint.json -p tsconfig.json --fix", "prebuild": "tslint -c tslint.json -p tsconfig.json --fix",
"build": "tsc", "build": "tsc",
"prestart": "npm run build", "prestart": "npm run build",
"start": "node .", "start": "node ./dist/main.js",
"test": "echo \"Error: no test specified\" && exit 1", "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/\"" "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'; ...@@ -5,12 +5,11 @@ import * as express from 'express';
import { createThriftServer } from '@creditkarma/thrift-server-express'; import { createThriftServer } from '@creditkarma/thrift-server-express';
const handler: ClientServiceHandler<express.Request> = new ClientServiceHandler<express.Request>(); const handler: ClientServiceHandler<express.Request> = new ClientServiceHandler<express.Request>();
const PORT = 8090;
export class ThriftServer { export class ThriftServer {
private app: express.Application; private app: express.Application;
constructor() { constructor(port: number) {
this.app = createThriftServer({ this.app = createThriftServer({
path: '/thrift', path: '/thrift',
thriftOptions: { thriftOptions: {
...@@ -18,8 +17,8 @@ export class ThriftServer { ...@@ -18,8 +17,8 @@ export class ThriftServer {
handler: new GameService.Processor(handler), handler: new GameService.Processor(handler),
}, },
}); });
this.app.listen(PORT, () => { this.app.listen(port, () => {
console.log(`Express server listening on port: ${PORT}`); console.log(`Thrift Express server listening on port: ${port}`);
}); });
} }
} }
......
...@@ -2,14 +2,15 @@ ...@@ -2,14 +2,15 @@
"compileOnSave": false, "compileOnSave": false,
"compilerOptions": { "compilerOptions": {
"baseUrl": "./", "baseUrl": "./",
"outDir": "./dist/out-tsc", "outDir": "./dist/",
"sourceMap": true, "sourceMap": true,
"declaration": false, "declaration": false,
"module": "ES6", "module": "CommonJs",
"moduleResolution": "node", "moduleResolution": "node",
"emitDecoratorMetadata": true, "emitDecoratorMetadata": true,
"experimentalDecorators": true, "experimentalDecorators": true,
"target": "ES5", "strict": true,
"target": "ES2017",
"typeRoots": [ "typeRoots": [
"node_modules/@types" "node_modules/@types"
], ],
......
...@@ -16,6 +16,10 @@ ...@@ -16,6 +16,10 @@
<name>Not Alone Server</name> <name>Not Alone Server</name>
<description>Spring Boot Not Alone server</description> <description>Spring Boot Not Alone server</description>
<properties>
<jacoco.version>0.8.5</jacoco.version>
</properties>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>fr.univnantes.alma</groupId> <groupId>fr.univnantes.alma</groupId>
...@@ -63,6 +67,36 @@ ...@@ -63,6 +67,36 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId> <artifactId>spring-boot-maven-plugin</artifactId>
</plugin> </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> </plugins>
</build> </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; ...@@ -3,14 +3,12 @@ package fr.univnantes.alma.server.user;
import fr.univnantes.alma.thrift.*; import fr.univnantes.alma.thrift.*;
import org.apache.thrift.TException; import org.apache.thrift.TException;
import java.util.List;
public class User { public class User {
private String id; private String id;
private String name; 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.id = id;
this.name = name; this.name = name;
this.service = service; this.service = service;
...@@ -19,7 +17,7 @@ public class User { ...@@ -19,7 +17,7 @@ public class User {
public User(String id, String name, String adress, int port) { public User(String id, String name, String adress, int port) {
this.id = id; this.id = id;
this.name = name; this.name = name;
this.service = new PlayerService(adress, port); this.service = new PlayerProxy(adress, port);
} }
public String getId() { public String getId() {
...@@ -30,7 +28,7 @@ public class User { ...@@ -30,7 +28,7 @@ public class User {
return name; return name;
} }
public PlayerService getService() { public PlayerProxy getService() {
return service; return service;
} }
......
...@@ -3,23 +3,32 @@ package fr.univnantes.alma.server.game; ...@@ -3,23 +3,32 @@ package fr.univnantes.alma.server.game;
import fr.univnantes.alma.data.DatabaseFactory; import fr.univnantes.alma.data.DatabaseFactory;
import fr.univnantes.alma.common.NotAloneDatabase; import fr.univnantes.alma.common.NotAloneDatabase;
import fr.univnantes.alma.server.game.item.Phase; 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.Board;
import fr.univnantes.alma.server.game.item.board.BoardColor; 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.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.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.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.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections;
import java.util.List; import java.util.List;
import static fr.univnantes.alma.server.game.item.card.CardName.*; import static fr.univnantes.alma.server.game.item.card.CardName.*;
import static fr.univnantes.alma.server.game.item.card.CardName.ARTEFACT; 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.*;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
public class GameTest { public class GameTest {
NotAloneDatabase database = DatabaseFactory.getDatabase(); NotAloneDatabase database = DatabaseFactory.getDatabase();
...@@ -27,6 +36,27 @@ public class GameTest { ...@@ -27,6 +36,27 @@ public class GameTest {
Planet planet; Planet planet;
Board board; 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());
<