Skip to content

Commit 6f3485f

Browse files
author
Manuel Perez Belmonte
committed
latest, 65%
1 parent f698435 commit 6f3485f

File tree

2 files changed

+40
-78
lines changed

2 files changed

+40
-78
lines changed

src/main/java/io/elastest/ece/application/PersistanceController.java

Lines changed: 0 additions & 53 deletions
This file was deleted.

src/test/java/elastest/io/ece/api/APIControllerTest.java

Lines changed: 40 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package elastest.io.ece.api;
22

3+
import com.google.gson.Gson;
4+
import com.google.gson.GsonBuilder;
35
import io.elastest.ece.application.APIController;
46
import io.elastest.ece.load.Loader;
57
import io.elastest.ece.load.model.HibernateCredentials;
@@ -22,6 +24,7 @@
2224
import org.springframework.test.context.web.WebAppConfiguration;
2325
import org.springframework.ui.ExtendedModelMap;
2426

27+
import java.util.ArrayList;
2528
import java.util.HashMap;
2629
import java.util.List;
2730

@@ -99,7 +102,7 @@ public void setup(){
99102
HashMap fixCost = new HashMap();
100103
fixCost.put("deployment", 0.0);
101104

102-
this.costModel = new CostModel("Free Cost Model", "ONDEMAND", fixCost, varCosts, null, "Everything for free, test purposes");
105+
this.costModel = new CostModel("Free Cost Model", "ONDEMAND", fixCost, varCosts, new HashMap<>(), "Everything for free, test purposes");
103106
this.hibernateClient.persistObject(costModel);
104107
}
105108

@@ -140,14 +143,17 @@ public void testGetCostModel() {
140143
double cpus = costModel.getVar_rate().get("cpus");
141144
double memory = costModel.getVar_rate().get("memory");
142145
double disk = costModel.getVar_rate().get("disk");
146+
ExtendedModelMap model = new ExtendedModelMap();
147+
Gson gson = new GsonBuilder().setPrettyPrinting().create();
143148

144149
apiController.addCostModel(name, description, fixName, fixValue, cpus, memory, disk, new ExtendedModelMap());
145150
List<CostModel> costModels = hibernateClient.executeQuery(QueryHelper.createListQuery(CostModel.class));
146151
int index = costModels.indexOf(costModel);
147152
Long id = costModels.get(index).getId();
148153
CostModel obtained = (CostModel) hibernateClient.getObject(CostModel.class, id);
149-
150-
assertEquals(obtained, costModel);
154+
apiController.getCostModel(String.valueOf(id), model);
155+
String costModelJson = (String) model.get("costModel");
156+
assertEquals(costModelJson, gson.toJson(costModel));
151157
}
152158

153159
@Test
@@ -184,6 +190,37 @@ public void testEstimatePost() {
184190
assertEquals(0d , cost);
185191
}
186192

193+
@Test
194+
public void testInit(){
195+
setup();
196+
apiController = new APIController();
197+
apiController.init();
198+
199+
logger.info("Mocking Cost Models Initialized in the init() method.");
200+
ArrayList<CostModel> result = new ArrayList();
201+
HashMap varCosts = new HashMap();
202+
varCosts.put("cpus", 50.0);
203+
varCosts.put("memory", 10.0);
204+
varCosts.put("disk", 1.0);
205+
HashMap fixCost = new HashMap();
206+
fixCost.put("deployment", 5.0);
207+
208+
CostModel costModel = new CostModel("On Demand 5 + Charges", "ONDEMAND", fixCost, varCosts, null, "On Demand 5 per deployment, 50 per core, 10 per GB ram and 1 per GB disk");
209+
210+
HashMap varCosts1 = new HashMap();
211+
varCosts1.put("cpus", 1.0);
212+
varCosts1.put("memory", 1.0);
213+
varCosts1.put("disk", 1.0);
214+
HashMap fixCost1 = new HashMap();
215+
fixCost1.put("deployment", 10.0);
216+
217+
CostModel costModel1 = new CostModel("On demand 10 + Charges", "ONDEMAND", fixCost1, varCosts1, null, "On Demand 10 per deployment, 1 per core, 1 per GB ram and 1 per GB disk");
218+
219+
List<CostModel> costModels = hibernateClient.executeQuery(QueryHelper.createListQuery(CostModel.class));
220+
assertTrue(costModels.contains(costModel));
221+
assertTrue(costModels.contains(costModel1));
222+
}
223+
187224
/**
188225
* Check and configure Hibernate
189226
*/
@@ -205,26 +242,4 @@ private static void checkAndConfigureHibernate() {
205242
System.exit(0);
206243
}
207244
}
208-
209-
// @Test
210-
// public void testGetCostModel() {
211-
// apiController = new APIController();
212-
//
213-
// assertEquals(apiController.getCostModel("costModel0", null), "redirection");
214-
// }
215-
//
216-
// @Test
217-
// public void testDeleteCostModel() {
218-
// apiController = new APIController();
219-
//
220-
// assertEquals(apiController.deleteCostModel("costModel0"), "redirection");
221-
// }
222-
//
223-
// @Test
224-
// public void testEstimatePost(){
225-
//
226-
// apiController = new APIController();
227-
//
228-
// assertEquals(apiController.estimatePost("costModel0"), "redirection");
229-
// }
230245
}

0 commit comments

Comments
 (0)