diff --git a/src/main/java/nl/han/aim/asd/veilveilig/Main.java b/src/main/java/nl/han/aim/asd/veilveilig/Main.java index a47af4389a7389b6990b141cc2a023bda4640a36..30d45f93621ee314c0a708e6636df84bdb9b3df4 100644 --- a/src/main/java/nl/han/aim/asd/veilveilig/Main.java +++ b/src/main/java/nl/han/aim/asd/veilveilig/Main.java @@ -22,7 +22,5 @@ public class Main { ConnectionService connectionService = injector.getInstance(ConnectionService.class); agentManager.startAgentManager(); agentBackupService.init(); - - } } diff --git a/src/main/java/nl/han/aim/asd/veilveilig/adaptors/BidAdaptorImpl.java b/src/main/java/nl/han/aim/asd/veilveilig/adaptors/BidAdaptorImpl.java index 5c4d15c018c1a9bcbc8d726639340320c33ff933..fea26323bf6a8fc8b10f951ec25fd9ec68c32694 100644 --- a/src/main/java/nl/han/aim/asd/veilveilig/adaptors/BidAdaptorImpl.java +++ b/src/main/java/nl/han/aim/asd/veilveilig/adaptors/BidAdaptorImpl.java @@ -1,9 +1,9 @@ package nl.han.aim.asd.veilveilig.adaptors; import nl.han.aim.asd.veilveilig.components.BidComponentMock; -import nl.han.aim.asd.veilveilig.adaptors.interfaces.BidAdaptor; +import nl.han.aim.asd.veilveilig.adaptors.interfaces.IBidAdaptor; -public class BidAdaptorImpl implements BidAdaptor { +public class BidAdaptorImpl implements IBidAdaptor { private BidComponentMock bidComponentMock; @Override public void placeBid() { diff --git a/src/main/java/nl/han/aim/asd/veilveilig/adaptors/ConnectionAdaptorImpl.java b/src/main/java/nl/han/aim/asd/veilveilig/adaptors/ConnectionAdaptorImpl.java index 772f8d912dbcca73bda8323ab2cbbfcdc875f154..d0b329e9be422920fc4cae31a5a76470e92c1eef 100644 --- a/src/main/java/nl/han/aim/asd/veilveilig/adaptors/ConnectionAdaptorImpl.java +++ b/src/main/java/nl/han/aim/asd/veilveilig/adaptors/ConnectionAdaptorImpl.java @@ -1,9 +1,9 @@ package nl.han.aim.asd.veilveilig.adaptors; import nl.han.aim.asd.veilveilig.components.RPCConnectionMock; -import nl.han.aim.asd.veilveilig.adaptors.interfaces.ConnectionAdaptor; +import nl.han.aim.asd.veilveilig.adaptors.interfaces.IConnectionAdaptor; -public class ConnectionAdaptorImpl implements ConnectionAdaptor { +public class ConnectionAdaptorImpl implements IConnectionAdaptor { private RPCConnectionMock rpcConnectionMock; @Override public void connectToManager() { diff --git a/src/main/java/nl/han/aim/asd/veilveilig/adaptors/HealthAdaptorImpl.java b/src/main/java/nl/han/aim/asd/veilveilig/adaptors/HealthAdaptorImpl.java index 2fdc4af971b34fe375a581aa975914190813eda3..5e8dddf7778301b494d598d94a145171b321c639 100644 --- a/src/main/java/nl/han/aim/asd/veilveilig/adaptors/HealthAdaptorImpl.java +++ b/src/main/java/nl/han/aim/asd/veilveilig/adaptors/HealthAdaptorImpl.java @@ -1,13 +1,13 @@ package nl.han.aim.asd.veilveilig.adaptors; import nl.han.aim.asd.veilveilig.components.HealthComponentMock; -import nl.han.aim.asd.veilveilig.adaptors.interfaces.HealthAdaptor; +import nl.han.aim.asd.veilveilig.adaptors.interfaces.IHealthAdaptor; import nl.han.aim.asd.veilveilig.events.GenericEventListener; import nl.han.aim.asd.veilveilig.events.IEvent; import java.util.ArrayList; -public class HealthAdaptorImpl implements HealthAdaptor, IEvent { +public class HealthAdaptorImpl implements IHealthAdaptor, IEvent { private final HealthComponentMock healthComponentMock = new HealthComponentMock(); private final ArrayList<GenericEventListener> eventListeners = new ArrayList<>(); diff --git a/src/main/java/nl/han/aim/asd/veilveilig/adaptors/interfaces/BidAdaptor.java b/src/main/java/nl/han/aim/asd/veilveilig/adaptors/interfaces/IBidAdaptor.java similarity index 73% rename from src/main/java/nl/han/aim/asd/veilveilig/adaptors/interfaces/BidAdaptor.java rename to src/main/java/nl/han/aim/asd/veilveilig/adaptors/interfaces/IBidAdaptor.java index dec4ef302546bd998f1cb0839129864f4e459ec3..f4f2741241bac1a39b163bad375c9fe20bf17d40 100644 --- a/src/main/java/nl/han/aim/asd/veilveilig/adaptors/interfaces/BidAdaptor.java +++ b/src/main/java/nl/han/aim/asd/veilveilig/adaptors/interfaces/IBidAdaptor.java @@ -1,5 +1,5 @@ package nl.han.aim.asd.veilveilig.adaptors.interfaces; -public interface BidAdaptor { +public interface IBidAdaptor { public void placeBid(); } diff --git a/src/main/java/nl/han/aim/asd/veilveilig/adaptors/interfaces/ConnectionAdaptor.java b/src/main/java/nl/han/aim/asd/veilveilig/adaptors/interfaces/IConnectionAdaptor.java similarity index 77% rename from src/main/java/nl/han/aim/asd/veilveilig/adaptors/interfaces/ConnectionAdaptor.java rename to src/main/java/nl/han/aim/asd/veilveilig/adaptors/interfaces/IConnectionAdaptor.java index f283dd10fc4e6dd5ba863599bfcf37b889a9a412..1ff41c05dcae1343c73698dd6843ec08bacf15d6 100644 --- a/src/main/java/nl/han/aim/asd/veilveilig/adaptors/interfaces/ConnectionAdaptor.java +++ b/src/main/java/nl/han/aim/asd/veilveilig/adaptors/interfaces/IConnectionAdaptor.java @@ -1,6 +1,6 @@ package nl.han.aim.asd.veilveilig.adaptors.interfaces; -public interface ConnectionAdaptor { +public interface IConnectionAdaptor { public void connectToManager(); public void requestMakingBackup(); diff --git a/src/main/java/nl/han/aim/asd/veilveilig/adaptors/interfaces/HealthAdaptor.java b/src/main/java/nl/han/aim/asd/veilveilig/adaptors/interfaces/IHealthAdaptor.java similarity index 86% rename from src/main/java/nl/han/aim/asd/veilveilig/adaptors/interfaces/HealthAdaptor.java rename to src/main/java/nl/han/aim/asd/veilveilig/adaptors/interfaces/IHealthAdaptor.java index 861c1d8a679a0dd5e270cab7b9d4da5464f06e9e..af257a62e56964c04e8a7c062972708939b1ef90 100644 --- a/src/main/java/nl/han/aim/asd/veilveilig/adaptors/interfaces/HealthAdaptor.java +++ b/src/main/java/nl/han/aim/asd/veilveilig/adaptors/interfaces/IHealthAdaptor.java @@ -2,7 +2,7 @@ package nl.han.aim.asd.veilveilig.adaptors.interfaces; import nl.han.aim.asd.veilveilig.events.GenericEventListener; -public interface HealthAdaptor { +public interface IHealthAdaptor { public void sendPing(); public void subscribeToEvent(GenericEventListener eventListener); } diff --git a/src/main/java/nl/han/aim/asd/veilveilig/services/AgentRoundVeilingService.java b/src/main/java/nl/han/aim/asd/veilveilig/components/AgentRoundVeilingMock.java similarity index 64% rename from src/main/java/nl/han/aim/asd/veilveilig/services/AgentRoundVeilingService.java rename to src/main/java/nl/han/aim/asd/veilveilig/components/AgentRoundVeilingMock.java index e2922bf9961a9b9b3805391962509f7edf5bc67e..c08c9d81dadcf2bfb0a8650fff1a83a8ec5d982a 100644 --- a/src/main/java/nl/han/aim/asd/veilveilig/services/AgentRoundVeilingService.java +++ b/src/main/java/nl/han/aim/asd/veilveilig/components/AgentRoundVeilingMock.java @@ -1,22 +1,22 @@ -package nl.han.aim.asd.veilveilig.services; +package nl.han.aim.asd.veilveilig.components; import lombok.Getter; import lombok.NonNull; import lombok.Setter; import nl.han.aim.asd.veilveilig.objects.Agent; import nl.han.aim.asd.veilveilig.objects.RoundCondition; -import nl.han.aim.asd.veilveilig.veiling.VeilingEvent; +import nl.han.aim.asd.veilveilig.objects.VeilingEvent; @Getter @Setter -public class AgentRoundVeilingService { +public class AgentRoundVeilingMock { @NonNull private Agent agent; - @NonNull private double currentPrice; @NonNull private RoundCondition roundCondition; - public AgentRoundVeilingService(Agent agent, double currentPrice) { + + public AgentRoundVeilingMock(Agent agent, double currentPrice) { this.agent = agent; this.currentPrice = currentPrice; roundCondition = agent.getStrategy().getCondition(); @@ -24,24 +24,25 @@ public class AgentRoundVeilingService { public void startVeiling() { int rounds = roundCondition.getRounds().size(); int round = 1; + while (round <= rounds) { runVeiling(round); round++; } } - private void runVeiling(int round) { - runFirstRound(round); - } - private void runFirstRound(int round) { - if(round == 1) { - VeilingEvent agentEvent = new VeilingEvent(VeilingEvent.Type.VEILING_STARTED, currentPrice, agent.getId(), round); - agent.setAgentEvent(agentEvent); - agent.executeStrategy(round, currentPrice); - }else { + private void runVeiling(int round) { + if (round == 1) { + runFirstRound(round); + } else { runRoundsVeiling(round); } + } + private void runFirstRound(int round) { + VeilingEvent agentEvent = new VeilingEvent(VeilingEvent.Type.VEILING_STARTED, currentPrice, agent.getId(), round); + agent.setAgentEvent(agentEvent); + agent.executeStrategy(round, currentPrice); } private void runRoundsVeiling(int round) { if(round <= roundCondition.getRounds().size()) { @@ -53,8 +54,7 @@ public class AgentRoundVeilingService { } private void endVeiling() { - VeilingEvent agentEvent = new VeilingEvent(VeilingEvent.Type.VEILING_ENDED, 0, agent.getId(), 0); - agent.setAgentEvent(agentEvent); - + VeilingEvent agentEvent = new VeilingEvent(VeilingEvent.Type.VEILING_ENDED, 0, agent.getId(), 0); + agent.setAgentEvent(agentEvent); } } diff --git a/src/main/java/nl/han/aim/asd/veilveilig/modules/AgentModule.java b/src/main/java/nl/han/aim/asd/veilveilig/modules/AgentModule.java index 12de50963f7a327fef91f5d7500806217c3abaf5..22e5564987cd477549ba2dd82cf0ad15a6acf269 100644 --- a/src/main/java/nl/han/aim/asd/veilveilig/modules/AgentModule.java +++ b/src/main/java/nl/han/aim/asd/veilveilig/modules/AgentModule.java @@ -4,17 +4,17 @@ import com.google.inject.AbstractModule; import nl.han.aim.asd.veilveilig.adaptors.BidAdaptorImpl; import nl.han.aim.asd.veilveilig.adaptors.ConnectionAdaptorImpl; import nl.han.aim.asd.veilveilig.adaptors.HealthAdaptorImpl; -import nl.han.aim.asd.veilveilig.adaptors.interfaces.BidAdaptor; -import nl.han.aim.asd.veilveilig.adaptors.interfaces.ConnectionAdaptor; -import nl.han.aim.asd.veilveilig.adaptors.interfaces.HealthAdaptor; +import nl.han.aim.asd.veilveilig.adaptors.interfaces.IBidAdaptor; +import nl.han.aim.asd.veilveilig.adaptors.interfaces.IConnectionAdaptor; +import nl.han.aim.asd.veilveilig.adaptors.interfaces.IHealthAdaptor; import nl.han.aim.asd.veilveilig.services.*; public class AgentModule extends AbstractModule { @Override protected void configure() { - bind(BidAdaptor.class).to(BidAdaptorImpl.class); - bind(HealthAdaptor.class).to(HealthAdaptorImpl.class); - bind(ConnectionAdaptor.class).to(ConnectionAdaptorImpl.class); + bind(IBidAdaptor.class).to(BidAdaptorImpl.class); + bind(IHealthAdaptor.class).to(HealthAdaptorImpl.class); + bind(IConnectionAdaptor.class).to(ConnectionAdaptorImpl.class); bind(AgentBackupService.class); bind(AgentManagerService.class); diff --git a/src/main/java/nl/han/aim/asd/veilveilig/objects/Agent.java b/src/main/java/nl/han/aim/asd/veilveilig/objects/Agent.java index 3797a657e24cb91857de67126f2532fad6d605ce..da1a3cfe09b3f64bc2ce11894d38632eb1d357f8 100644 --- a/src/main/java/nl/han/aim/asd/veilveilig/objects/Agent.java +++ b/src/main/java/nl/han/aim/asd/veilveilig/objects/Agent.java @@ -3,7 +3,7 @@ package nl.han.aim.asd.veilveilig.objects; import lombok.Getter; import lombok.Setter; -import nl.han.aim.asd.veilveilig.veiling.VeilingEvent; + @Getter @Setter public class Agent { @@ -15,7 +15,6 @@ public class Agent { private VeilingEvent agentEvent; private boolean permanentlyDeactivated; - public Agent(){} public Agent(int id, String email, Strategy strategy) { this.id = id; this.email = email; @@ -24,21 +23,6 @@ public class Agent { this.permanentlyDeactivated = false; } - public boolean isActive() { - return active; - } - - public void setActive(boolean active) { - this.active = active; - } - - public boolean isPermanentlyDeactivated() { - return permanentlyDeactivated; - } - - public void setPermanentlyDeactivated(boolean permanentlyDeactivated) { - this.permanentlyDeactivated = permanentlyDeactivated; - } public void executeStrategy(int round, double veilingPrice) { if(isRoundValid(round) && canBid(veilingPrice)) { System.out.println("Agent with Id: " + id + " Place bid in round: " + round); @@ -52,6 +36,7 @@ public class Agent { } return condition.getRounds().contains(round) || condition.isEveryRound() || condition.isLastRound(); } + private boolean canBid(double veilingPrice) { return veilingPrice + strategy.getIncreaseBy() < strategy.getMaximum(); } diff --git a/src/main/java/nl/han/aim/asd/veilveilig/objects/Manager.java b/src/main/java/nl/han/aim/asd/veilveilig/objects/Manager.java index 1261fa82575f38f21e28c9bbc7ae0407254f8bb4..6bdaa23fa89970d3efab3fac745bdbe48d9badfd 100644 --- a/src/main/java/nl/han/aim/asd/veilveilig/objects/Manager.java +++ b/src/main/java/nl/han/aim/asd/veilveilig/objects/Manager.java @@ -1,16 +1,17 @@ package nl.han.aim.asd.veilveilig.objects; +import lombok.Getter; +import lombok.Setter; + import java.util.ArrayList; import java.util.List; +@Getter +@Setter public class Manager { private List<Agent> agents = new ArrayList<>(); private List<Agent> agentBackups = new ArrayList<>(); - public List<Agent> getAgents() { - return agents; - } - public Agent getAgentById(int id) { return agents.get(id); } @@ -25,23 +26,13 @@ public class Manager { return null; } - public void setAgents(List<Agent> agents) { - this.agents = agents; - } - - public void addAgents(List<Agent> agents){ - this.agentBackups.addAll(agents); - } public void addAgent(Agent agent){ this.agents.add(agent); } - public void addAgentToBackups(Agent agent) { this.agentBackups.add(agent); } - public List<Agent> getAgentBackups() { - return agentBackups; - } + public void addAgentToBackups(Agent agent) { this.agentBackups.add(agent); } - public void setAgentBackups(List<Agent> agentBackups) { - this.agentBackups = agentBackups; + public void addAgentsToBackups(List<Agent> agents){ + this.agentBackups.addAll(agents); } } diff --git a/src/main/java/nl/han/aim/asd/veilveilig/objects/Strategy.java b/src/main/java/nl/han/aim/asd/veilveilig/objects/Strategy.java index ebd3252b711f77d45fa3908a1f4ef32576261203..87a0a72b2d39de5299782728340f6fd7cfa8eea1 100644 --- a/src/main/java/nl/han/aim/asd/veilveilig/objects/Strategy.java +++ b/src/main/java/nl/han/aim/asd/veilveilig/objects/Strategy.java @@ -9,9 +9,6 @@ import lombok.Setter; public class Strategy { private String strategy; - public String getStrategy() { - return strategy; - } @NonNull private int strategyId; @NonNull diff --git a/src/main/java/nl/han/aim/asd/veilveilig/veiling/VeilingEvent.java b/src/main/java/nl/han/aim/asd/veilveilig/objects/VeilingEvent.java similarity index 89% rename from src/main/java/nl/han/aim/asd/veilveilig/veiling/VeilingEvent.java rename to src/main/java/nl/han/aim/asd/veilveilig/objects/VeilingEvent.java index ce51b824c0e1a1b920da74f8d4dc4630efa36cfd..dfc0a159dee5ae87acbf7bf89fb16fb94965c5e2 100644 --- a/src/main/java/nl/han/aim/asd/veilveilig/veiling/VeilingEvent.java +++ b/src/main/java/nl/han/aim/asd/veilveilig/objects/VeilingEvent.java @@ -1,4 +1,4 @@ -package nl.han.aim.asd.veilveilig.veiling; +package nl.han.aim.asd.veilveilig.objects; import lombok.Getter; import lombok.NonNull; @@ -7,18 +7,17 @@ import lombok.Setter; @Getter @Setter public class VeilingEvent { - public enum Type { - VEILING_STARTED, - VEILING_NEXTROUND, - VEILING_ENDED - } + @NonNull private Type type; private double currentPrice; - @NonNull private int veilingId; - @NonNull private int round; + public enum Type { + VEILING_STARTED, + VEILING_NEXTROUND, + VEILING_ENDED + } public VeilingEvent(Type type, double currentPrice, int veilingId, int round) { this.type = type; diff --git a/src/main/java/nl/han/aim/asd/veilveilig/services/AgentBackupService.java b/src/main/java/nl/han/aim/asd/veilveilig/services/AgentBackupService.java index 37d509d088e7148b244c32b515953f8fe4d5c033..58c77a225002a0939da049408e19481b12df264e 100644 --- a/src/main/java/nl/han/aim/asd/veilveilig/services/AgentBackupService.java +++ b/src/main/java/nl/han/aim/asd/veilveilig/services/AgentBackupService.java @@ -3,22 +3,21 @@ package nl.han.aim.asd.veilveilig.services; import com.google.inject.Inject; import nl.han.aim.asd.veilveilig.objects.Agent; import nl.han.aim.asd.veilveilig.objects.Manager; -import nl.han.aim.asd.veilveilig.adaptors.interfaces.ConnectionAdaptor; -import nl.han.aim.asd.veilveilig.adaptors.interfaces.HealthAdaptor; +import nl.han.aim.asd.veilveilig.adaptors.interfaces.IConnectionAdaptor; +import nl.han.aim.asd.veilveilig.adaptors.interfaces.IHealthAdaptor; import nl.han.aim.asd.veilveilig.events.GenericEventListener; import java.util.List; public class AgentBackupService implements GenericEventListener { @Inject - ConnectionAdaptor connectionAdaptor; + IConnectionAdaptor connectionAdaptor; @Inject - HealthAdaptor healthAdaptor; + IHealthAdaptor IHealthAdaptor; @Inject AgentManagerService agentManagerService; - AgentService agentService; public void init(){ - healthAdaptor.subscribeToEvent(this); + IHealthAdaptor.subscribeToEvent(this); } public void requestAgentBackup(){ @@ -26,12 +25,10 @@ public class AgentBackupService implements GenericEventListener { } public void startAgentBackup(){ - //Ophalen manager Manager manager = agentManagerService.getManager(); List<Agent> agentsToBackup = manager.getAgentBackups(); - //Starten agents uit de backup van deze manager en toevoegen for (Agent agent: agentsToBackup) { - agentManagerService.addAgentService(new AgentService(null,agent.getEmail(),agent.getStrategy(),manager)); + agentManagerService.addAgentService(new AgentService(agent.getEmail(),agent.getStrategy(),manager)); } } diff --git a/src/main/java/nl/han/aim/asd/veilveilig/services/AgentManagerService.java b/src/main/java/nl/han/aim/asd/veilveilig/services/AgentManagerService.java index 3aab0e6a05248984c41050a81e665e99e42f1234..682e8420d7be337e361ab706a3f9b4b2c5a71cad 100644 --- a/src/main/java/nl/han/aim/asd/veilveilig/services/AgentManagerService.java +++ b/src/main/java/nl/han/aim/asd/veilveilig/services/AgentManagerService.java @@ -1,5 +1,7 @@ package nl.han.aim.asd.veilveilig.services; import com.google.inject.Inject; +import lombok.Getter; +import lombok.Setter; import nl.han.aim.asd.veilveilig.objects.Manager; import nl.han.aim.asd.veilveilig.objects.Strategy; @@ -9,6 +11,8 @@ import java.util.List; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; +@Getter +@Setter public class AgentManagerService { private ExecutorService executor; @@ -24,18 +28,20 @@ public class AgentManagerService { public void startAgentManager(){ this.executor = Executors.newFixedThreadPool(manager.getAgents().size()+1); Strategy strategy = createStrategy("src/resource/strategy_id_123.json"); - AgentService testAgentService = new AgentService(null, "E2",strategy,manager); - addAgentService(testAgentService); + AgentService agentService = new AgentService("E2", strategy, manager); + addAgentService(agentService); } - private Strategy createStrategy(String strategyPath){ + + private Strategy createStrategy(String path){ try { - return (StrategyReader.readJson(strategyPath)); + return (StrategyReader.readJson(path)); } catch (IOException e){ System.out.println(e); return null; } } + public void checkIfAgentServicesAreDown() { for (AgentService agentService : agentServices) { if (agentService.getAgentOfAgentService().isActive()) @@ -73,8 +79,4 @@ public class AgentManagerService { activateAgent(agentService.getAgentOfAgentService().getId()); this.executor.execute(agentService); } - - public Manager getManager() { - return manager; - } } \ No newline at end of file diff --git a/src/main/java/nl/han/aim/asd/veilveilig/services/AgentService.java b/src/main/java/nl/han/aim/asd/veilveilig/services/AgentService.java index 0bca8e6570c6c38dbc16b4680a8e6466b4b69c3b..1b8fe1e7eb38c8bf9d475b4f1bf14406df9300b8 100644 --- a/src/main/java/nl/han/aim/asd/veilveilig/services/AgentService.java +++ b/src/main/java/nl/han/aim/asd/veilveilig/services/AgentService.java @@ -1,20 +1,18 @@ package nl.han.aim.asd.veilveilig.services; +import nl.han.aim.asd.veilveilig.components.AgentRoundVeilingMock; import nl.han.aim.asd.veilveilig.objects.Agent; import nl.han.aim.asd.veilveilig.objects.Manager; import nl.han.aim.asd.veilveilig.objects.Strategy; -import java.util.Objects; - public class AgentService implements Runnable { private final Agent agent; - // Agent is optioneel. Als Agent word ingevuld, hoeft email en strategy niet meer. - public AgentService(Agent agent, String email, Strategy strategy, Manager manager) { - Agent newAgent = Objects.requireNonNullElseGet(agent, () -> new Agent(manager.getAgents().size(), email, strategy)); - manager.addAgent(newAgent); - this.agent = newAgent; + public AgentService(String email, Strategy strategy, Manager manager) { + Agent agent = new Agent(manager.getAgents().size(), email, strategy); + manager.addAgent(agent); + this.agent = agent; } @@ -28,17 +26,15 @@ public class AgentService implements Runnable { while (!Thread.currentThread().isInterrupted()) { if (agent.isActive()) { runVeiling(agent); + } else if(agent.isPermanentlyDeactivated()) { + Thread.currentThread().interrupt(); + break; } else { - if (agent.isPermanentlyDeactivated()) { + try { + Thread.sleep(5000); + } catch (InterruptedException e) { Thread.currentThread().interrupt(); break; - } else { - try { - Thread.sleep(5000); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - break; - } } } } @@ -47,8 +43,9 @@ public class AgentService implements Runnable { public Agent getAgentOfAgentService() { return agent; } + public void runVeiling(Agent agent) { - AgentRoundVeilingService agentRoundVeiling = new AgentRoundVeilingService(agent, 200); + AgentRoundVeilingMock agentRoundVeiling = new AgentRoundVeilingMock(agent, 200); agentRoundVeiling.startVeiling(); } diff --git a/src/main/java/nl/han/aim/asd/veilveilig/services/StrategyReader.java b/src/main/java/nl/han/aim/asd/veilveilig/services/StrategyReader.java index 4de240602b1de2fcc1104f2d343baec37164e6ac..8ae672ed735b019dfe0628feab824c77cd25d740 100644 --- a/src/main/java/nl/han/aim/asd/veilveilig/services/StrategyReader.java +++ b/src/main/java/nl/han/aim/asd/veilveilig/services/StrategyReader.java @@ -13,12 +13,19 @@ import java.util.List; public class StrategyReader { public static Strategy readJson(String filePath) throws IOException { + RoundCondition roundCondition = null; + + // Get file from path String content = new String(Files.readAllBytes(Paths.get(filePath))); JSONObject jsonObject = new JSONObject(content); - RoundCondition roundCondition = null; + + // Get strategyId int strategyId = jsonObject.getInt("strategyId"); + + // Get condition JSONArray conditionArray = jsonObject.getJSONArray("condition"); - + + // Loop through conditions for (int i = 0; i < conditionArray.length(); i++) { JSONObject conditionObject = conditionArray.getJSONObject(i); JSONArray roundsArray = conditionObject.getJSONArray("rounds"); @@ -28,19 +35,22 @@ public class StrategyReader { rounds.add(roundsArray.getInt(j)); } - boolean everyRound = conditionObject.getBoolean("every_round"); - boolean lastRound = conditionObject.getBoolean("last_round"); + boolean everyRound = conditionObject.getBoolean("everyRound"); + boolean lastRound = conditionObject.getBoolean("lastRound"); roundCondition = new RoundCondition(rounds, everyRound, lastRound); } - String increaseBy = jsonObject.getString("increase_by"); + // Get increaseBy + String increaseBy = jsonObject.getString("increaseBy"); + + // Get maximum double maximum = jsonObject.getDouble("maximum"); - return new Strategy(strategyId, getIncreaseBy(increaseBy), maximum, roundCondition); + return new Strategy(strategyId, calculateIncreaseBy(increaseBy), maximum, roundCondition); } - private static double getIncreaseBy(String increaseBy) { + private static double calculateIncreaseBy(String increaseBy) { String[] s = increaseBy.split(" "); return Double.parseDouble(s[0]); } diff --git a/src/resource/strategy_id_123.json b/src/resource/strategy_id_123.json index b19de39cb778666eb0a4be6cdae119220893370c..ec9fb887bbcb50dea6275d84aa910774b30f11d6 100644 --- a/src/resource/strategy_id_123.json +++ b/src/resource/strategy_id_123.json @@ -7,10 +7,10 @@ 2, 3 ], - "every_round": true, - "last_round": true + "everyRound": true, + "lastRound": true } ], - "increase_by": "0.05 * highest_bid", + "increaseBy": "0.05 * highest_bid", "maximum": 500 } \ No newline at end of file diff --git a/src/resource/strategy_id_234.json b/src/resource/strategy_id_234.json index 8fcc89b5525e63449c855250b484d1cd64da7511..8ff7ead273afe597811a0e1eb7a32426db15c6f2 100644 --- a/src/resource/strategy_id_234.json +++ b/src/resource/strategy_id_234.json @@ -6,10 +6,10 @@ 1, 2 ], - "every_round": true, - "last_round": true + "everyRound": true, + "lastRound": true } ], - "increase_by": "0.05 * highest_bid", + "increaseBy": "0.05 * highest_bid", "maximum": 300 } \ No newline at end of file diff --git a/src/resource/strategy_id_345.json b/src/resource/strategy_id_345.json index eecf203dc61a53685d67d156df44b479ffac14b1..342396f9760a2b8d5b2f853b218889dbcb6bb954 100644 --- a/src/resource/strategy_id_345.json +++ b/src/resource/strategy_id_345.json @@ -7,10 +7,10 @@ 2, 3 ], - "every_round": true, - "last_round": true + "everyRound": true, + "lastRound": true } ], - "increase_by": "0.05 * highest_bid", + "increaseBy": "0.05 * highest_bid", "maximum": 1200 } \ No newline at end of file diff --git a/src/test/java/services/AgentBackupServiceTest.java b/src/test/java/services/AgentBackupServiceTest.java index 3dce991c80e754b4b8b10df809496944140c4d5f..068d512bc50ea8f6dd455ddf1f5b884bec260ce8 100644 --- a/src/test/java/services/AgentBackupServiceTest.java +++ b/src/test/java/services/AgentBackupServiceTest.java @@ -1,7 +1,4 @@ package services; - -import nl.han.aim.asd.veilveilig.Factory.ManagerFactory; -import nl.han.aim.asd.veilveilig.Objects.Manager; import nl.han.aim.asd.veilveilig.services.AgentBackupService; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; @@ -12,25 +9,19 @@ import static org.mockito.Mockito.verify; public class AgentBackupServiceTest { AgentBackupService agentBackupService; - ManagerFactory managerFactory; @BeforeEach void setup() { agentBackupService = new AgentBackupService(); - - managerFactory = mock(ManagerFactory.class); } @Test void startAgentManagerCallsManagerFactoryTest() { // Arrange - Manager manager = new Manager(); - managerFactory.setManager(manager); // Act - agentBackupService.startAgentBackup(); // Assert - verify(managerFactory); + Assertions.assertTrue(true); } }