incubator-nuvem-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sag...@apache.org
Subject svn commit: r1141168 - in /incubator/nuvem/trunk: nuvem-api/src/main/java/org/apache/nuvem/cloud/dataService/ nuvem-google/src/main/java/org/apache/nuvem/cloud/dataService/ nuvem-google/src/main/java/org/apache/nuvem/cloud/dataService/impl/ nuvem-googl...
Date Wed, 29 Jun 2011 17:13:23 GMT
Author: sagara
Date: Wed Jun 29 17:13:22 2011
New Revision: 1141168

URL: http://svn.apache.org/viewvc?rev=1141168&view=rev
Log:
Applied first patch for NUVEM-9 - Google Data Service support.

Added:
    incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/dataService/
    incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/dataService/DataService.java
    incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/dataService/DataServiceException.java
    incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/dataService/Element.java
    incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/dataService/Feature.java
    incubator/nuvem/trunk/nuvem-google/src/main/java/org/apache/nuvem/cloud/dataService/
    incubator/nuvem/trunk/nuvem-google/src/main/java/org/apache/nuvem/cloud/dataService/impl/
    incubator/nuvem/trunk/nuvem-google/src/main/java/org/apache/nuvem/cloud/dataService/impl/GoogleDataServiceImpl.java
    incubator/nuvem/trunk/nuvem-google/src/test/java/org/apache/nuvem/cloud/dataService/
    incubator/nuvem/trunk/nuvem-google/src/test/java/org/apache/nuvem/cloud/dataService/impl/
    incubator/nuvem/trunk/nuvem-google/src/test/java/org/apache/nuvem/cloud/dataService/impl/GoogleDataServiceImplTest.java

Added: incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/dataService/DataService.java
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/dataService/DataService.java?rev=1141168&view=auto
==============================================================================
--- incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/dataService/DataService.java
(added)
+++ incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/dataService/DataService.java
Wed Jun 29 17:13:22 2011
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.nuvem.cloud.dataService;
+
+import org.oasisopen.sca.annotation.Remotable;
+
+/**
+ * The Interface DataService.
+ */
+@Remotable
+public interface DataService {
+	
+	/**
+	 * Creates the element.
+	 *
+	 * @param element the element
+	 * @return the element
+	 * @throws DataServiceException the data service exception
+	 */
+	public Element createElement(Element element) throws DataServiceException;
+	
+	/**
+	 * Update element.
+	 *
+	 * @param element the element
+	 * @return the element
+	 * @throws DataServiceException the data service exception
+	 */
+	public Element updateElement(Element element) throws DataServiceException;
+	
+	/**
+	 * Gets the element.
+	 *
+	 * @param kind the kind
+	 * @param id the id
+	 * @return the element
+	 * @throws DataServiceException the data service exception
+	 */
+	public Element getElement(String kind,String id) throws DataServiceException;
+	
+	/**
+	 * Delete element.
+	 *
+	 * @param element the element
+	 * @return true, if successful
+	 * @throws DataServiceException the data service exception
+	 */
+	public boolean deleteElement(Element element) throws DataServiceException;
+	
+
+}

Added: incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/dataService/DataServiceException.java
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/dataService/DataServiceException.java?rev=1141168&view=auto
==============================================================================
--- incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/dataService/DataServiceException.java
(added)
+++ incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/dataService/DataServiceException.java
Wed Jun 29 17:13:22 2011
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.nuvem.cloud.dataService;
+
+/**
+ * The Class DataServiceException.
+ */
+public class DataServiceException extends Exception {
+	
+	/**
+	 * Instantiates a new data service exception.
+	 */
+	public DataServiceException(){
+		
+	}
+	
+	/**
+	 * Instantiates a new data service exception.
+	 *
+	 * @param cause the cause
+	 */
+	public DataServiceException(Throwable cause){		
+		        super(cause);		   
+	}
+	
+	
+
+}

Added: incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/dataService/Element.java
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/dataService/Element.java?rev=1141168&view=auto
==============================================================================
--- incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/dataService/Element.java
(added)
+++ incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/dataService/Element.java
Wed Jun 29 17:13:22 2011
@@ -0,0 +1,199 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.nuvem.cloud.dataService;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+
+/**
+ * The Class Element.
+ */
+public class Element {
+	
+	/** The features. */
+	private Set<Feature> features;
+	
+	/** The type. */
+	private String type;
+	
+	/** The id. */
+	private String id;
+	
+	/** The key. */
+	private String key;
+	
+	/** The persist. */
+	private boolean persist;
+	
+	/**
+	 * Checks if is persist.
+	 *
+	 * @return true, if is persist
+	 */
+	public boolean isPersist() {
+		return persist;
+	}
+
+	/**
+	 * Sets the persist.
+	 */
+	public void setPersist() {
+		this.persist = true;
+	}
+
+	/**
+	 * Instantiates a new element.
+	 *
+	 * @param type the type
+	 */
+	public Element(String type){
+		this.type = type;
+		this.persist = false;
+		this.features = new HashSet<Feature>();
+	}
+	
+	/**
+	 * Instantiates a new element.
+	 *
+	 * @param type the type
+	 * @param features the features
+	 */
+	public Element(String type, Set<Feature> features){
+		this.type = type;
+		this.features=features;
+		
+	}	
+   
+	/**
+	 * Sets the key.
+	 *
+	 * @param key the new key
+	 */
+	public void setKey(String key) {
+		this.key = key;
+	}
+
+	/**
+	 * Gets the id.
+	 *
+	 * @return the id
+	 */
+	public String getId() {
+		return id;
+	}
+
+	/**
+	 * Sets the id.
+	 *
+	 * @param id the new id
+	 */
+	public void setId(String id) {
+		this.id = id;
+	}
+
+	/**
+	 * Gets the key.
+	 *
+	 * @return the key
+	 */
+	public String getKey() {
+		if(key == null){
+			setKey(getType().concat("(").concat(getId()).concat(")"));
+		}
+		return key;
+	}
+
+	/**
+	 * Gets the type.
+	 *
+	 * @return the type
+	 */
+	public String getType() {
+		return type;
+	}
+
+	/**
+	 * Sets the type.
+	 *
+	 * @param type the new type
+	 */
+	public void setType(String type) {
+		this.type = type;
+	}
+
+	/**
+	 * Instantiates a new element.
+	 *
+	 * @param featuresList the features list
+	 */
+	public Element(List<Feature> featuresList){
+		this.features = new HashSet<Feature>(featuresList);
+		
+	}
+	
+	/**
+	 * Adds the feature.
+	 *
+	 * @param feature the feature
+	 */
+	public void addFeature(Feature feature){
+		getFeatures().add(feature);
+	}
+	
+	/**
+	 * Adds the feature.
+	 *
+	 * @param name the name
+	 * @param propValue the prop value
+	 */
+	public void addFeature(String name,Object propValue){
+		getFeatures().add(new Feature(name,propValue));
+	}
+	
+	/**
+	 * Removes the feature.
+	 *
+	 * @param feature the feature
+	 */
+	public void removeFeature(Feature feature){
+		getFeatures().remove(feature);
+	}
+	
+
+	/**
+	 * Gets the features.
+	 *
+	 * @return the features
+	 */
+	public Set<Feature> getFeatures() {
+		return features;
+	}
+
+	/**
+	 * Sets the features.
+	 *
+	 * @param features the new features
+	 */
+	public void setFeatures(Set<Feature> features) {
+		this.features = features;
+	}
+
+}

Added: incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/dataService/Feature.java
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/dataService/Feature.java?rev=1141168&view=auto
==============================================================================
--- incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/dataService/Feature.java
(added)
+++ incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/dataService/Feature.java
Wed Jun 29 17:13:22 2011
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.nuvem.cloud.dataService;
+
+/**
+ * The Class Feature.
+ */
+public class Feature {
+	
+	/** The name. */
+	String name;
+	
+	/** The value. */
+	Object value;
+	
+	/**
+	 * Instantiates a new feature.
+	 */
+	public Feature(){
+		
+	}
+	
+	/**
+	 * Instantiates a new feature.
+	 *
+	 * @param name the name
+	 * @param propValue the prop value
+	 */
+	public Feature(String name, Object propValue){
+		this.name=name;
+		this.value=propValue;
+	}
+	
+	/**
+	 * Gets the name.
+	 *
+	 * @return the name
+	 */
+	public String getName() {
+		return name;
+	}
+	
+	/**
+	 * Sets the name.
+	 *
+	 * @param name the new name
+	 */
+	public void setName(String name) {
+		this.name = name;
+	}
+	
+	/**
+	 * Gets the value.
+	 *
+	 * @return the value
+	 */
+	public Object getValue() {
+		return value;
+	}
+	
+	/**
+	 * Sets the value.
+	 *
+	 * @param value the new value
+	 */
+	public void setValue(String value) {
+		this.value = value;
+	}
+	
+	
+
+}

Added: incubator/nuvem/trunk/nuvem-google/src/main/java/org/apache/nuvem/cloud/dataService/impl/GoogleDataServiceImpl.java
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-google/src/main/java/org/apache/nuvem/cloud/dataService/impl/GoogleDataServiceImpl.java?rev=1141168&view=auto
==============================================================================
--- incubator/nuvem/trunk/nuvem-google/src/main/java/org/apache/nuvem/cloud/dataService/impl/GoogleDataServiceImpl.java
(added)
+++ incubator/nuvem/trunk/nuvem-google/src/main/java/org/apache/nuvem/cloud/dataService/impl/GoogleDataServiceImpl.java
Wed Jun 29 17:13:22 2011
@@ -0,0 +1,156 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.nuvem.cloud.dataService.impl;
+
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.nuvem.cloud.dataService.DataService;
+import org.apache.nuvem.cloud.dataService.DataServiceException;
+import org.apache.nuvem.cloud.dataService.Element;
+import org.apache.nuvem.cloud.dataService.Feature;
+
+import com.google.appengine.api.datastore.DatastoreService;
+import com.google.appengine.api.datastore.Entity;
+import com.google.appengine.api.datastore.EntityNotFoundException;
+import com.google.appengine.api.datastore.Key;
+import com.google.appengine.api.datastore.KeyFactory;
+
+/**
+ * The Class GoogleDataServiceImpl.
+ */
+public class GoogleDataServiceImpl implements DataService {
+
+	/** The datastore service. */
+	private DatastoreService datastoreService;	
+
+	/**
+	 * Instantiates a new google data service impl.
+	 *
+	 * @param datastoreService the datastore service
+	 */
+	public GoogleDataServiceImpl(DatastoreService datastoreService) {
+		this.datastoreService = datastoreService;
+	}
+
+	/**
+	 * Gets the datastore service.
+	 *
+	 * @return the datastore service
+	 */
+	public DatastoreService getDatastoreService() {
+		return datastoreService;
+	}
+
+	/**
+	 * Sets the datastore service.
+	 *
+	 * @param datastoreService the new datastore service
+	 */
+	public void setDatastoreService(DatastoreService datastoreService) {
+		this.datastoreService = datastoreService;
+	}
+
+	/* (non-Javadoc)
+	 * @see org.apache.nuvem.cloud.dataService.DataService#createElement(org.apache.nuvem.cloud.dataService.Element)
+	 */
+	@Override
+	public Element createElement(Element element) throws DataServiceException {
+
+		Entity entity = new Entity(element.getType());
+		Iterator<Feature> feIterator = element.getFeatures().iterator();
+		while (feIterator.hasNext()) {
+			Feature feature = feIterator.next();
+			entity.setProperty(feature.getName(), feature.getValue());
+		}
+		Key key = datastoreService.put(entity);
+		element.setId(String.valueOf(key.getId()));
+		element.setPersist();
+		System.out.println(key);
+		return element;
+	}
+
+	/* (non-Javadoc)
+	 * @see org.apache.nuvem.cloud.dataService.DataService#updateElement(org.apache.nuvem.cloud.dataService.Element)
+	 */
+	@Override
+	public Element updateElement(Element element) throws DataServiceException {
+		try {
+			Key key = KeyFactory.createKey(element.getType(), Long.parseLong(element.getId()));
+			Entity entity = new Entity(key);
+			Iterator<Feature> feIterator = element.getFeatures().iterator();
+			while (feIterator.hasNext()) {
+				Feature feature = feIterator.next();
+				entity.setProperty(feature.getName(), feature.getValue());
+			}				
+			Key keyRet = datastoreService.put(entity);
+			element.setId(String.valueOf(keyRet.getId()));
+			element.setPersist();
+			System.out.println(keyRet);
+			return element;
+
+		} catch (Exception e) {
+			throw new DataServiceException(e);
+		}
+
+	}
+
+	/* (non-Javadoc)
+	 * @see org.apache.nuvem.cloud.dataService.DataService#getElement(java.lang.String, java.lang.String)
+	 */
+	@Override
+	public Element getElement(String kind,String id) throws DataServiceException {		
+		try {
+			Key key=KeyFactory.createKey(kind, Long.parseLong(id));
+			Entity entity = datastoreService.get(key);
+			Element element= new Element(entity.getKind());
+			element.setId(String.valueOf(entity.getKey().getId()));
+			Map<String,Object> properties = entity.getProperties();
+			Iterator<String> propKeyItr = properties.keySet().iterator();
+			while(propKeyItr.hasNext()){
+				String propName = propKeyItr.next();
+				Object propValue = properties.get(propName);
+				element.addFeature(propName, propValue);				
+			}
+			element.setPersist();
+			return element;
+		} catch (EntityNotFoundException e) {
+			throw new DataServiceException(e);
+		}
+	}
+
+	/* (non-Javadoc)
+	 * @see org.apache.nuvem.cloud.dataService.DataService#deleteElement(org.apache.nuvem.cloud.dataService.Element)
+	 */
+	@Override
+	public boolean deleteElement(Element element) throws DataServiceException {
+		try {
+			Key key=KeyFactory.createKey(element.getType(), Long.parseLong(element.getId()));
+			datastoreService.delete(key);
+			return true;
+
+		} catch (Exception e) {
+			throw new DataServiceException(e);
+		}
+	}
+
+	
+
+}

Added: incubator/nuvem/trunk/nuvem-google/src/test/java/org/apache/nuvem/cloud/dataService/impl/GoogleDataServiceImplTest.java
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-google/src/test/java/org/apache/nuvem/cloud/dataService/impl/GoogleDataServiceImplTest.java?rev=1141168&view=auto
==============================================================================
--- incubator/nuvem/trunk/nuvem-google/src/test/java/org/apache/nuvem/cloud/dataService/impl/GoogleDataServiceImplTest.java
(added)
+++ incubator/nuvem/trunk/nuvem-google/src/test/java/org/apache/nuvem/cloud/dataService/impl/GoogleDataServiceImplTest.java
Wed Jun 29 17:13:22 2011
@@ -0,0 +1,168 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.nuvem.cloud.dataService.impl;
+
+import static org.junit.Assert.*;
+
+import org.apache.nuvem.cloud.dataService.DataService;
+import org.apache.nuvem.cloud.dataService.DataServiceException;
+import org.apache.nuvem.cloud.dataService.Element;
+import org.apache.nuvem.cloud.dataService.Feature;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.google.appengine.api.datastore.DatastoreService;
+import com.google.appengine.api.datastore.DatastoreServiceFactory;
+import com.google.appengine.api.datastore.Entity;
+import com.google.appengine.api.datastore.Key;
+import com.google.appengine.api.datastore.Query;
+import com.google.appengine.tools.development.testing.LocalDatastoreServiceTestConfig;
+import com.google.appengine.tools.development.testing.LocalServiceTestHelper;
+
+
+/**
+ * The Class GoogleDataServiceImplTest.
+ */
+public class GoogleDataServiceImplTest {
+	
+	/** The data service. */
+	private DataService dataService ;
+	
+	/** The ds. */
+	private DatastoreService ds;
+
+	/** The helper. */
+	private final LocalServiceTestHelper helper =
+	        new LocalServiceTestHelper(new LocalDatastoreServiceTestConfig());
+
+
+	/**
+	 * Sets the up.
+	 *
+	 * @throws Exception the exception
+	 */
+	@Before
+	public void setUp() throws Exception {
+		helper.setUp();
+		ds = DatastoreServiceFactory.getDatastoreService();
+		dataService = new GoogleDataServiceImpl(ds);
+	}
+
+	/**
+	 * Tear down.
+	 *
+	 * @throws Exception the exception
+	 */
+	@After
+	public void tearDown() throws Exception {
+		helper.tearDown();
+	}
+
+	/**
+	 * Test create element.
+	 *
+	 * @throws DataServiceException the data service exception
+	 */
+	@Test
+	public void testCreateElement() throws DataServiceException {
+		
+		Element e1= new Element("student");
+		e1.addFeature("name", "saman");
+		Feature f1= new Feature("age",12);
+		e1.addFeature(f1);
+		dataService.createElement(e1);
+		assertEquals(1, ds.prepare(new Query("student")).countEntities());
+		
+		
+		
+	}
+
+	/**
+	 * Test update element.
+	 *
+	 * @throws DataServiceException the data service exception
+	 */
+	@Test
+	public void testUpdateElement() throws DataServiceException {
+		
+		Entity entity = new Entity("student");
+		entity.setProperty("name", "saman");
+		entity.setProperty("age",12);
+		Key key = ds.put(entity);
+		assertEquals(1, ds.prepare(new Query("student")).countEntities());
+		
+		Element e1= new Element("student");
+		e1.addFeature("name", "saman");
+		Feature f1= new Feature("age",12);		
+		e1.addFeature(f1);
+		e1.addFeature("countrt", "SL");
+		e1.setType(key.getKind());
+		e1.setId(String.valueOf(key.getId()));			
+		dataService.updateElement(e1);
+		assertEquals(1, ds.prepare(new Query("student")).countEntities());
+		
+	}
+
+	/**
+	 * Test get element.
+	 *
+	 * @throws DataServiceException the data service exception
+	 */
+	@Test
+	public void testGetElement() throws DataServiceException {
+
+		Entity entity = new Entity("student");
+		entity.setProperty("name", "saman");
+		entity.setProperty("age",12);
+		Key key = ds.put(entity);
+		assertEquals(1, ds.prepare(new Query("student")).countEntities());		
+		Element e2 = dataService.getElement(key.getKind(),String.valueOf(key.getId()));
+		assertNotNull(e2);
+	}
+
+	/**
+	 * Test delete element.
+	 *
+	 * @throws DataServiceException the data service exception
+	 */
+	@Test
+	public void testDeleteElement() throws DataServiceException {
+
+		Entity entity = new Entity("student");
+		entity.setProperty("name", "saman");
+		entity.setProperty("age",12);
+		Key key = ds.put(entity);
+		assertEquals(1, ds.prepare(new Query("student")).countEntities());
+		
+		Element e1= new Element("student");
+		e1.addFeature("name", "saman");
+		Feature f1= new Feature("age","12");		
+		e1.addFeature(f1);
+		e1.addFeature("countrt", "SL");
+		e1.setType(key.getKind());
+		e1.setId(String.valueOf(key.getId()));			
+		dataService.updateElement(e1);
+		dataService.deleteElement(e1);
+		assertEquals(0, ds.prepare(new Query("student")).countEntities());
+		
+	}
+
+}



Mime
View raw message