Skip to content

Commit 0871081

Browse files
author
Manuel Perez Belmonte
committed
API tests
1 parent 7d50007 commit 0871081

File tree

4 files changed

+113
-29
lines changed

4 files changed

+113
-29
lines changed

pom.xml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,37 @@
168168
</environmentVariables>
169169
</configuration>
170170
</plugin>
171+
<!--<plugin>-->
172+
<!--<groupId>org.codehaus.mojo</groupId>-->
173+
<!--<artifactId>cobertura-maven-plugin</artifactId>-->
174+
<!--<version>2.7</version>-->
175+
<!--<executions>-->
176+
<!--<execution>-->
177+
<!--<phase>test</phase>-->
178+
<!--<goals>-->
179+
<!--<goal>cobertura</goal>-->
180+
<!--</goals>-->
181+
<!--</execution>-->
182+
<!--</executions>-->
183+
<!--</plugin>-->
171184
</plugins>
172185
</build>
186+
187+
<!--<reporting>-->
188+
<!--<plugins>-->
189+
<!--<plugin>-->
190+
<!--<groupId>org.codehaus.mojo</groupId>-->
191+
<!--<artifactId>cobertura-maven-plugin</artifactId>-->
192+
<!--<version>2.7</version>-->
193+
<!--<configuration>-->
194+
<!--<check></check>-->
195+
<!--<formats>-->
196+
<!--<format>html</format>-->
197+
<!--<format>xml</format>-->
198+
<!--</formats>-->
199+
<!--</configuration>-->
200+
<!--</plugin>-->
201+
<!--</plugins>-->
202+
<!--</reporting>-->
203+
173204
</project>

src/main/java/io/elastest/ece/model/CostModel.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,19 +115,15 @@ public void setComponents(Map<String, String> components) {
115115

116116
@Override
117117
public boolean equals(Object o) {
118-
119118
if (o == this) return true;
120119
if (!(o instanceof CostModel)) {
121120
return false;
122121
}
123-
124122
CostModel costModel = (CostModel) o;
125-
126123
return (costModel.getName().equals(((CostModel) o).getName())
127124
&& costModel.getType().equals(((CostModel) o).getType())
128125
&& costModel.getVar_rate().equals(((CostModel) o).getVar_rate())
129126
&& costModel.getFix_cost().equals(((CostModel) o).getFix_cost())
130-
&& costModel.getComponents().equals(((CostModel) o).getComponents())
131127
&& costModel.getDescription().equals(((CostModel) o).getDescription()));
132128
}
133129
}

src/main/java/io/elastest/ece/model/TJob.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,16 @@ public Map<String, String> getMetadata() {
7777
public void setMetadata(Map<String, String> metadata) {
7878
this.metadata = metadata;
7979
}
80+
81+
@Override
82+
public boolean equals(Object o) {
83+
if (o == this) return true;
84+
if (!(o instanceof TJob)) {
85+
return false;
86+
}
87+
TJob tjob = (TJob) o;
88+
return (tjob.getName().equals(((TJob) o).getName())
89+
&& tjob.getMetadata().equals(((TJob) o).getMetadata()));
90+
// && tjob.getDescription().equals(((TJob) o).getDescription()));
91+
}
8092
}

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

Lines changed: 70 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import io.elastest.ece.persistance.QueryHelper;
1111
import junit.framework.TestCase;
1212
import junit.framework.TestSuite;
13+
import org.hibernate.Query;
1314
import org.hibernate.cfg.Configuration;
1415
import org.junit.Before;
1516
import org.junit.Test;
@@ -71,6 +72,16 @@ public void setup(){
7172
logger.info("Setting up the Database connection.");
7273
checkAndConfigureHibernate();
7374
hibernateClient = HibernateClient.getInstance();
75+
List<CostModel> oldCostModels = hibernateClient.executeQuery(QueryHelper.createListQuery(CostModel.class));
76+
for(CostModel costModel : oldCostModels){
77+
hibernateClient.deleteObject(costModel);
78+
}
79+
80+
List<TJob> oldTjobs = hibernateClient.executeQuery(QueryHelper.createListQuery(TJob.class));
81+
for(TJob tJob : oldTjobs){
82+
hibernateClient.deleteObject(tJob);
83+
}
84+
7485
logger.info("Creating Demo T-Job Values.");
7586
HashMap<String, String> test0Map = new HashMap<>();
7687
test0Map.put("cpus", "8.0");
@@ -82,13 +93,13 @@ public void setup(){
8293

8394
logger.info("Creating Demo Cost Model Values.");
8495
HashMap varCosts = new HashMap();
85-
varCosts.put("cpus", 50.0);
86-
varCosts.put("memory", 10.0);
87-
varCosts.put("disk", 1.0);
96+
varCosts.put("cpus", 0.0);
97+
varCosts.put("memory", 0.0);
98+
varCosts.put("disk", 0.0);
8899
HashMap fixCost = new HashMap();
89-
fixCost.put("deployment", 10.0);
100+
fixCost.put("deployment", 0.0);
90101

91-
this.costModel = new CostModel("On Demand 10 + Charges", "ONDEMAND", fixCost, varCosts, null, "On Demand 5 per deployment, 50 per core, 10 per GB ram and 1 per GB disk");
102+
this.costModel = new CostModel("Free Cost Model", "ONDEMAND", fixCost, varCosts, null, "Everything for free, test purposes");
92103
this.hibernateClient.persistObject(costModel);
93104
}
94105

@@ -118,26 +129,60 @@ public void testAddCostModel() {
118129
assertTrue(costModels.contains(costModel));
119130
}
120131

121-
// @Test
122-
// public void testGetCostModel() {
123-
// setup();
124-
// apiController = new APIController();
125-
// String name = costModel.getName();
126-
// String description = costModel.getDescription();
127-
// String fixName = (String) costModel.getFix_cost().keySet().toArray()[0];
128-
// Double fixValue = costModel.getFix_cost().get(fixName);
129-
// double cpus = costModel.getVar_rate().get("cpus");
130-
// double memory = costModel.getVar_rate().get("memory");
131-
// double disk = costModel.getVar_rate().get("disk");
132-
//
133-
// apiController.addCostModel(name, description, fixName, fixValue, cpus, memory, disk, new ExtendedModelMap());
134-
// List<CostModel> costModels = hibernateClient.executeQuery(QueryHelper.createListQuery(CostModel.class));
135-
// int index = costModels.indexOf(costModel);
136-
// Long id = costModels.get(index).getId();
137-
// CostModel obtained = (CostModel) hibernateClient.getObject(CostModel.class, id);
138-
//
139-
// assertEquals(obtained, costModel);
140-
// }
132+
@Test
133+
public void testGetCostModel() {
134+
setup();
135+
apiController = new APIController();
136+
String name = costModel.getName();
137+
String description = costModel.getDescription();
138+
String fixName = (String) costModel.getFix_cost().keySet().toArray()[0];
139+
Double fixValue = costModel.getFix_cost().get(fixName);
140+
double cpus = costModel.getVar_rate().get("cpus");
141+
double memory = costModel.getVar_rate().get("memory");
142+
double disk = costModel.getVar_rate().get("disk");
143+
144+
apiController.addCostModel(name, description, fixName, fixValue, cpus, memory, disk, new ExtendedModelMap());
145+
List<CostModel> costModels = hibernateClient.executeQuery(QueryHelper.createListQuery(CostModel.class));
146+
int index = costModels.indexOf(costModel);
147+
Long id = costModels.get(index).getId();
148+
CostModel obtained = (CostModel) hibernateClient.getObject(CostModel.class, id);
149+
150+
assertEquals(obtained, costModel);
151+
}
152+
153+
@Test
154+
public void testDeleteCostModel() {
155+
setup();
156+
apiController = new APIController();
157+
List<CostModel> costModels = hibernateClient.executeQuery(QueryHelper.createListQuery(CostModel.class));
158+
int index = costModels.indexOf(costModel);
159+
Long id = costModels.get(index).getId();
160+
161+
apiController.deleteCostModel(String.valueOf(id));
162+
163+
assertEquals(null, hibernateClient.getObject(CostModel.class, id));
164+
}
165+
166+
@Test
167+
public void testEstimatePost() {
168+
setup();
169+
apiController = new APIController();
170+
171+
List<CostModel> costModels = hibernateClient.executeQuery(QueryHelper.createListQuery(CostModel.class));
172+
int costModelIndex = costModels.indexOf(costModel);
173+
Long costModelId = costModels.get(costModelIndex).getId();
174+
175+
List<TJob> tJobs = hibernateClient.executeQuery(QueryHelper.createListQuery(TJob.class));
176+
int tJobIndex = tJobs.indexOf(tJob);
177+
Long tJobId = tJobs.get(tJobIndex).getId();
178+
179+
ExtendedModelMap model = new ExtendedModelMap();
180+
apiController.estimatePost(String.valueOf(tJobId), String.valueOf(costModelId), model);
181+
182+
Double cost = (Double) model.get("estimate");
183+
184+
assertEquals(0d , cost);
185+
}
141186

142187
/**
143188
* Check and configure Hibernate

0 commit comments

Comments
 (0)