Skip to content

Commit

Permalink
Modifying Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aldrinleal committed Dec 16, 2012
1 parent eaf134e commit ca48393
Show file tree
Hide file tree
Showing 8 changed files with 403 additions and 22 deletions.
4 changes: 4 additions & 0 deletions .gitignore
@@ -0,0 +1,4 @@
.project
.settings
.classpath
target
6 changes: 6 additions & 0 deletions readability-metrics-core/.project
Expand Up @@ -15,8 +15,14 @@
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.springframework.ide.eclipse.core.springbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.springframework.ide.eclipse.core.springnature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
Expand Down
6 changes: 6 additions & 0 deletions readability-metrics-webapp/.project
Expand Up @@ -15,8 +15,14 @@
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.springframework.ide.eclipse.core.springbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.springframework.ide.eclipse.core.springnature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
Expand Down
167 changes: 167 additions & 0 deletions readability-metrics-webapp/readability-metrics-configuration.xml
@@ -0,0 +1,167 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<api xmlns="http://mashape.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://mashape.com http://www.mashape.com/schema/mashape-4.0.xsd">
<endpoint name="Debug Client" group="Diagnostics" http="GET">
<route>/debug</route>
<description>See https://github.com/ipeirotis/ReadabilityMetrics/wiki/REST-API:-Diagnostics</description>
<parameters/>
<response type="List[Debug Client Model]"/>
</endpoint>
<endpoint name="Delete Text" group="Resources" http="DELETE">
<route>/text/{id}</route>
<description>See https://github.com/ipeirotis/ReadabilityMetrics/wiki/REST-API:-Managing-Texts</description>
<parameters>
<parameter type="string" optional="false" name="id">
<description></description>
<example>2c7c3d5f244f1a40069a32224215e0cf9b42485c99d80f357d76f006359c7a18</example>
</parameter>
</parameters>
<response type="string"/>
<errors>
<error type="string" code="404">
<description>Text Not Found</description>
</error>
</errors>
</endpoint>
<endpoint name="Get Named Metric" group="Metrics" http="GET">
<route>/text/{id}/metrics/{name}</route>
<description>See https://github.com/ipeirotis/ReadabilityMetrics/wiki/REST-API:-Retrieving-Text-Metrics</description>
<parameters>
<parameter type="string" optional="false" name="id">
<description>Text Id</description>
<example>o8m0zyetzixyml6g8buhv8vydpag3i:6e048c8dceff8f5591829c39900504e83e6b9179a092a09adb3e5212328c07fc</example>
</parameter>
<parameter type="string" optional="false" name="name">
<description>Metric Name</description>
<example>ARI</example>
</parameter>
</parameters>
<response type="List[Get Text Metrics Model]"/>
<errors>
<error type="string" code="404">
<description>Not Found</description>
</error>
</errors>
</endpoint>
<endpoint name="Get Text Metrics" group="Metrics" http="GET">
<route>/text/{id}/metrics</route>
<description>See https://github.com/ipeirotis/ReadabilityMetrics/wiki/REST-API:-Retrieving-Text-Metrics </description>
<parameters>
<parameter type="string" optional="false" name="id">
<description>Text Id</description>
<example>o8m0zyetzixyml6g8buhv8vydpag3i:6e048c8dceff8f5591829c39900504e83e6b9179a092a09adb3e5212328c07fc</example>
</parameter>
</parameters>
<response type="List[Get Text Metrics Model]"/>
</endpoint>
<endpoint name="Retrieve Text" group="Resources" http="GET">
<route>/text/{id}</route>
<description>See https://github.com/ipeirotis/ReadabilityMetrics/wiki/REST-API:-Managing-Texts</description>
<parameters>
<parameter type="string" optional="false" name="id">
<description>SHA-256 Hex Hash of Content (Lowercase)</description>
<example>2c7c3d5f244f1a40069a32224215e0cf9b42485c99d80f357d76f006359c7a18</example>
</parameter>
</parameters>
<response type="Text"/>
</endpoint>
<endpoint name="Submit Text" group="Resources" http="POST">
<route>/text</route>
<description>See https://github.com/ipeirotis/ReadabilityMetrics/wiki/REST-API:-Managing-Texts</description>
<parameters>
<parameter type="string" optional="false" name="body">
<description>Body Text</description>
<example>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</example>
</parameter>
</parameters>
<response type="List[Text]"/>
<errors>
<error type="string" code="404">
<description>Entity Not Found</description>
</error>
</errors>
</endpoint>
<endpoint name="findAll" group="Resources" http="GET">
<route>/text</route>
<description>List All Texts - See https://github.com/ipeirotis/ReadabilityMetrics/wiki/REST-API:-Managing-Texts</description>
<parameters/>
<response type="List[Text]"/>
</endpoint>
<model name="Debug Client Model">
<description></description>
<example>{
&quot;Host&quot;: [
&quot;ipeirotis-hrd.appspot.com:80&quot;
],
&quot;Accept&quot;: [
&quot;application/json&quot;
],
&quot;X-Forwarded-For&quot;: [
&quot;23.23.3.43, 23.21.68.63&quot;
],
&quot;x-forwarded-port&quot;: [
&quot;443&quot;
],
&quot;x-forwarded-proto&quot;: [
&quot;https&quot;
],
&quot;X-Mashape-Version&quot;: [
&quot;2.3.5&quot;
],
&quot;X-Mashape-User-PublicKey&quot;: [
&quot;o8m0zyetzixyml6g8buhv8vydpag3i&quot;
],
&quot;X-Mashape-User&quot;: [
&quot;aldrinleal&quot;
],
&quot;User-Agent&quot;: [
&quot;mashape-java/2.0&quot;
],
&quot;X-AppEngine-Country&quot;: [
&quot;US&quot;
],
&quot;X-AppEngine-Region&quot;: [
&quot;ny&quot;
],
&quot;X-AppEngine-City&quot;: [
&quot;new york&quot;
],
&quot;X-AppEngine-CityLatLong&quot;: [
&quot;40.714353,-74.005973&quot;
]
}</example>
<fields/>
</model>
<model name="Get Text Metrics Model">
<description>See https://github.com/ipeirotis/ReadabilityMetrics/wiki/REST-API:-Retrieving-Text-Metrics</description>
<example>{
&quot;id&quot;: &quot;o8m0zyetzixyml6g8buhv8vydpag3i:6e048c8dceff8f5591829c39900504e83e6b9179a092a09adb3e5212328c07fc&quot;,
&quot;metrics&quot;: {
&quot;ARI&quot;: 39.201
}
}</example>
<fields>
<simple type="string" optional="false" name="id">
<description>o8m0zyetzixyml6g8buhv8vydpag3i:6e048c8dceff8f5591829c39900504e83e6b9179a092a09adb3e5212328c07fc</description>
</simple>
</fields>
</model>
<model name="Text">
<description>Represents a Stored Text</description>
<example>{
&quot;id&quot;: &quot;o8m0zyetzixyml6g8buhv8vydpag3i:6e048c8dceff8f5591829c39900504e83e6b9179a092a09adb3e5212328c07fc&quot;,
&quot;content&quot;: &quot;Lorem+ipsum+dolor+sit+amet%2C+consectetur+adipisicing+elit%2C+sed+do+eiusmod+tempor+incididunt+ut+labore+et+dolore+magna+aliqua.+Ut+enim+ad+minim+veniam%2C+quis+nostrud+exercitation+ullamco+laboris+nisi+ut+aliquip+ex+ea+commodo+consequat.+Duis+aute+irure+dolor+in+reprehenderit+in+voluptate+velit+esse+cillum+dolore+eu+fugiat+nulla+pariatur.+Excepteur+sint+occaecat+cupidatat+non+proident%2C+sunt+in+culpa+qui+officia+deserunt+mollit+anim+id+est+laborum.&quot;,
&quot;owner&quot;: &quot;o8m0zyetzixyml6g8buhv8vydpag3i&quot;
}</example>
<fields>
<simple type="string" optional="false" name="content">
<description>Lorem+ipsum+dolor+sit+amet%2C+consectetur+adipisicing+elit%2C+sed+do+eiusmod+tempor+incididunt+ut+labore+et+dolore+magna+aliqua.+Ut+enim+ad+minim+veniam%2C+quis+nostrud+exercitation+ullamco+laboris+nisi+ut+aliquip+ex+ea+commodo+consequat.+Duis+aute+irure+dolor+in+reprehenderit+in+voluptate+velit+esse+cillum+dolore+eu+fugiat+nulla+pariatur.+Excepteur+sint+occaecat+cupidatat+non+proident%2C+sunt+in+culpa+qui+officia+deserunt+mollit+anim+id+est+laborum.</description>
</simple>
<simple type="string" optional="false" name="id">
<description>o8m0zyetzixyml6g8buhv8vydpag3i:6e048c8dceff8f5591829c39900504e83e6b9179a092a09adb3e5212328c07fc</description>
</simple>
<simple type="string" optional="false" name="owner">
<description>o8m0zyetzixyml6g8buhv8vydpag3i</description>
</simple>
</fields>
</model>
</api>
Expand Up @@ -26,6 +26,11 @@ abstract class BaseResource {
@Autowired
UserService userService;

/**
* Retrieves or creates (if supplied) the User Entity
*
* @return User object
*/
Key<User> getOwner() {
if (null == user)
return null;
Expand Down
Expand Up @@ -27,6 +27,12 @@
import com.ipeirotis.readability.service.TextMetricService;
import com.ipeirotis.readability.service.TextService;

/**
* Represents the Text Manipulation Resource
*
* @author aldrin
*
*/
@Component
@Scope("request")
@Produces(MediaType.APPLICATION_JSON_VALUE)
Expand All @@ -40,7 +46,12 @@ public class TextResource extends BaseResource {

@Autowired
ReadabilityService readabilityService;


/**
* Handler needed for CORS support
*
* @return CORS Response
*/
@OPTIONS
@Path(".*")
public Response getOptionsForUpdateText() throws Exception {
Expand All @@ -53,6 +64,13 @@ public Response getOptionsForUpdateText() throws Exception {
.build();
}

/**
* Updates (read: stores) a Text
*
* @param contents
* Body Context (Form Method)
* @return Created Text Object
*/
@POST
public Text updateText(String contents) throws Exception {
@SuppressWarnings("unused")
Expand All @@ -61,7 +79,7 @@ public Text updateText(String contents) throws Exception {
if (contents.startsWith("body=")) {
contents = contents.substring("body=".length());
}

t = new Text(user, contents);

if (null == (o = textService.findFirstByPrimaryKey(t.getId()))) {
Expand All @@ -72,6 +90,14 @@ public Text updateText(String contents) throws Exception {
return t;
}

/**
* Given an Id, returns the Text
*
* @param id
* id, in the form &lt;userid&gt:&lt;sha1hash&gt;
*
* @return Text Object
*/
@Path("/{id : [^/]+}")
@GET
public Text findById(@PathParam("id") String id) throws Exception {
Expand All @@ -83,6 +109,13 @@ public Text findById(@PathParam("id") String id) throws Exception {
return t;
}

/**
* Returns the text metrics for given id
*
* @param id
* id, in the form &lt;userid&gt:&lt;sha1hash&gt;
* @return Json Array of Object Id + Metrics
*/
@Path("/{id : [^/]+}/metrics")
@GET
public Map<String, Object> findMetricsById(@PathParam("id") String id)
Expand All @@ -103,6 +136,15 @@ public Map<String, Object> findMetricsById(@PathParam("id") String id)
return result;
}

/**
* Returns a Named Metric
*
* @param id
* id, in the form &lt;userid&gt:&lt;sha1hash&gt;
* @param metricType
* metric type (ARI, CHARACTERS, SYLLABLES, ...)
* @return Named Metric (just like the example in findMetricsById
*/
@Path("/{id : [^/]+}/metrics/{metricType : \\w+}")
@GET
public Map<String, Object> findNamedMetricsById(@PathParam("id") String id,
Expand All @@ -114,7 +156,8 @@ public Map<String, Object> findNamedMetricsById(@PathParam("id") String id,

Map<String, BigDecimal> metrics = new LinkedHashMap<String, BigDecimal>();

TextMetric m = textMetricService.findFirstByPrimaryKey(String.format("%s:%s", t.getId(), metricType));
TextMetric m = textMetricService.findFirstByPrimaryKey(String.format(
"%s:%s", t.getId(), metricType));

metrics.put(m.getMetricType(), m.getValue());

Expand All @@ -123,6 +166,13 @@ public Map<String, Object> findNamedMetricsById(@PathParam("id") String id,
return result;
}

/**
* Deletes a Text
*
* @param id
* id, in the form &lt;userid&gt:&lt;sha1hash&gt;
* @return Text Data, prior to removal
*/
@Path("/{id : [^/]+}")
@DELETE
public Text deleteById(@PathParam("id") String id) throws Exception {
Expand All @@ -136,6 +186,11 @@ public Text deleteById(@PathParam("id") String id) throws Exception {
return t;
}

/**
* Returns all texts which belongs to this user
*
* @return array of Text Objects
*/
@GET
public Collection<Text> findAll() {
return Lists.newArrayList(textService.findAllByParentKey(user.getId()));
Expand Down

0 comments on commit ca48393

Please sign in to comment.