public class DocumentStore
extends java.lang.Object
DocumentStore.xml
specification. This uses the State Pattern (a Design Pattern from Gamma,
et al.) for its implementation. All requests are delegated to an abstract
State, which has concrete subclasses LoggedOut and LoggedIn, which respond
to certain requests and ignore others. This is a good implementation
strategy to ensure that no information is returned by a service, when it
is in an inappropriate state.
Otherwise, the DocumentStore consists of a Map from customers to their own private storage space; the space consists of indexed Document sets, where each index maps to a List of versions of the Document. Each customer has previously registered and is given an SLA specifying a storage allocation, in terabytes, and an encryption standard. This example uses a witness-type for the Document, and also demonstrates how a service may throw exceptions. This service defines two kinds of RuntimeException, which mimic "Not Found" kinds of http error. These are thrown under suitable conditions, such that the test-driver must expect these exceptions during testing.
Suggestions are given for how to modify the source code to seed faults deliberately, which will be detected during testing.
Constructor and Description |
---|
DocumentStore()
Creates this DocumentStore.
|
Modifier and Type | Method and Description |
---|---|
java.lang.Integer |
deleteVersion(java.lang.Integer docid,
java.lang.Integer version)
If LoggedIn, attempts to delete a Document with the given docid and
version number.
|
Document |
getDocument(java.lang.Integer docid)
If LoggedIn, attempts to retrieve a Document with the given docid.
|
java.lang.Integer |
getEncryption()
If LoggedIn, enacts getEncryption/ok and returns the encryption
standard for the customer.
|
java.lang.String |
getScenario()
Returns the last scenario that was enacted.
|
java.lang.String |
getState()
Returns the last state that was entered.
|
java.lang.Integer |
getStorageLimit()
If LoggedIn, enacts getStorageLimit/ok and returns the allocated
storage for the customer.
|
java.lang.Integer |
getStorageUsed()
If LoggedIn, enacts getStorageUsed/ok and returns the storage used
by the customer.
|
Document |
getVersion(java.lang.Integer docid,
java.lang.Integer version)
If LoggedIn, attempts to retrieve a Document with the given docid and
version number.
|
java.lang.Object[] |
login(java.lang.String username,
java.lang.String password)
If LoggedOut, attempts to login with the given credentials.
|
void |
logout()
If LoggedIn, enacts logout/ok, clears the current customer's cached
information and enters the LoggedOut state.
|
java.lang.Object[] |
putDocument(java.lang.Integer docid,
Document document)
If LoggedIn, attempts to store a Document against the given docid.
|
public DocumentStore()
public java.lang.String getScenario()
public java.lang.String getState()
public java.lang.Object[] login(java.lang.String username, java.lang.String password)
username
- the username of a customer.password
- the password of this user.public void logout()
public java.lang.Integer getEncryption()
public java.lang.Integer getStorageLimit()
public java.lang.Integer getStorageUsed()
public java.lang.Object[] putDocument(java.lang.Integer docid, Document document) throws BadDocumentIdentifier
docid
- the index of the Document.document
- the Document.BadDocumentIdentifier
- if an out-of-range docid was provided.public Document getDocument(java.lang.Integer docid) throws BadDocumentIdentifier, BadVersionIdentifier
docid
- the index of the Document.BadDocumentIdentifier
- if an out-of-range docid was provided.BadVersionIdentifier
- if no versions of this Document exist.public Document getVersion(java.lang.Integer docid, java.lang.Integer version) throws BadDocumentIdentifier, BadVersionIdentifier
docid
- the index of the Document.version
- the version number.BadDocumentIdentifier
- if an out-of-range docid was provided.BadVersionIdentifier
- if an out-of-range version was provided.public java.lang.Integer deleteVersion(java.lang.Integer docid, java.lang.Integer version) throws BadDocumentIdentifier, BadVersionIdentifier
docid
- the index of the Document.version
- the version number.BadDocumentIdentifier
- if an out-of-range docid was provided.BadVersionIdentifier
- if an out-of-range version was provided.