forked from gwestersf/QualityFoundry
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Greg Wester
committed
Jul 18, 2012
1 parent
e867824
commit 6334320
Showing
6 changed files
with
245 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
// Copyright (c) 2012 Gregory D. Wester | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
package com.force.taas.qf.model; | ||
|
||
import java.util.Date; | ||
|
||
import javax.xml.bind.annotation.XmlRootElement; | ||
|
||
/** | ||
* | ||
* @author gwester | ||
* | ||
*/ | ||
@XmlRootElement | ||
public class TestResult { | ||
public TestStatusEnum status; | ||
public Date reportDateTime; | ||
public int runTimeInMillis; | ||
public String fullClassName; | ||
public String testName; | ||
public String result; | ||
|
||
public TestResult() { } | ||
|
||
public TestResult(TestStatusEnum status, Date reportDateTime, | ||
int runTimeInMillis, String fullClassName, String testName, | ||
String result) { | ||
this.status = status; | ||
this.reportDateTime = reportDateTime; | ||
this.runTimeInMillis = runTimeInMillis; | ||
this.fullClassName = fullClassName; | ||
this.testName = testName; | ||
this.result = result; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
final int prime = 31; | ||
int result = 1; | ||
result = prime * result | ||
+ ((fullClassName == null) ? 0 : fullClassName.hashCode()); | ||
result = prime * result | ||
+ ((reportDateTime == null) ? 0 : reportDateTime.hashCode()); | ||
result = prime * result | ||
+ ((testName == null) ? 0 : testName.hashCode()); | ||
return result; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (this == obj) | ||
return true; | ||
if (obj == null) | ||
return false; | ||
if (getClass() != obj.getClass()) | ||
return false; | ||
TestResult other = (TestResult) obj; | ||
if (fullClassName == null) { | ||
if (other.fullClassName != null) | ||
return false; | ||
} else if (!fullClassName.equals(other.fullClassName)) | ||
return false; | ||
if (reportDateTime == null) { | ||
if (other.reportDateTime != null) | ||
return false; | ||
} else if (!reportDateTime.equals(other.reportDateTime)) | ||
return false; | ||
if (testName == null) { | ||
if (other.testName != null) | ||
return false; | ||
} else if (!testName.equals(other.testName)) | ||
return false; | ||
return true; | ||
} | ||
|
||
public String getKey() { | ||
return String.valueOf(hashCode()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright (c) 2012 Gregory D. Wester | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
package com.force.taas.qf.model; | ||
|
||
import javax.xml.bind.annotation.XmlEnum; | ||
|
||
/** | ||
* | ||
* @author gwester | ||
* | ||
*/ | ||
@XmlEnum(String.class) | ||
public enum TestStatusEnum { | ||
SUCCESS, | ||
FAILURE, | ||
SKIPPED, | ||
ERROR; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package com.force.taas.qf; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
import java.io.OutputStreamWriter; | ||
import java.io.StringWriter; | ||
import java.io.Writer; | ||
import java.net.URI; | ||
import java.util.Date; | ||
|
||
import javax.xml.bind.JAXBContext; | ||
import javax.xml.bind.Marshaller; | ||
import javax.xml.stream.XMLStreamWriter; | ||
|
||
import org.apache.http.HttpResponse; | ||
import org.apache.http.client.HttpClient; | ||
import org.apache.http.client.methods.HttpPut; | ||
import org.apache.http.client.utils.URIBuilder; | ||
import org.apache.http.entity.StringEntity; | ||
import org.apache.http.impl.client.DefaultHttpClient; | ||
import org.codehaus.jettison.mapped.Configuration; | ||
import org.codehaus.jettison.mapped.MappedNamespaceConvention; | ||
import org.codehaus.jettison.mapped.MappedXMLStreamWriter; | ||
import org.glassfish.grizzly.http.server.HttpServer; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import com.force.taas.qf.model.TestResult; | ||
import com.force.taas.qf.model.TestStatusEnum; | ||
|
||
public class PersistenceTest { | ||
private HttpServer httpServer; | ||
|
||
@Before | ||
public void setUp() throws IOException { | ||
httpServer = WebServer.startServer(); | ||
} | ||
|
||
@After | ||
public void tearDown() { | ||
httpServer.stop(); | ||
httpServer = null; | ||
} | ||
|
||
@Test | ||
public void testPutInDb() throws Exception { | ||
TestResult recentResult = new TestResult(TestStatusEnum.SUCCESS, new Date(System.currentTimeMillis()), | ||
0, "MyTestClazz", "myTest", | ||
"`T`Loglines"); | ||
|
||
HttpClient client = new DefaultHttpClient(); | ||
URIBuilder builder = new URIBuilder(); | ||
builder.setScheme("http").setHost("localhost").setPort(9998).setPath("/tests"); | ||
URI uri = builder.build(); | ||
HttpPut request = new HttpPut(uri); | ||
request.setHeader("Content-Type", "application/json"); | ||
request.setHeader("Accept", "application/json"); | ||
|
||
JAXBContext jc = JAXBContext.newInstance(TestResult.class); | ||
Marshaller marshaller = jc.createMarshaller(); | ||
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); | ||
StringWriter writer = new StringWriter(); | ||
XMLStreamWriter xmlStreamWriter = new MappedXMLStreamWriter(new MappedNamespaceConvention(new Configuration()), writer); | ||
|
||
marshaller.marshal(recentResult, xmlStreamWriter); | ||
request.setEntity(new StringEntity(writer.toString())); | ||
HttpResponse response = client.execute(request); | ||
|
||
assertEquals("Wrong HTTP response code", 204, response.getStatusLine().getStatusCode()); | ||
} | ||
} |