Improve comment management

feature/appm-store/pbac
lasanthaDLPDS 6 years ago
parent 2fd7601139
commit e5ef68fa3c

@ -21,8 +21,6 @@ package org.wso2.carbon.device.application.mgt.common;
import org.wso2.carbon.device.application.mgt.common.jaxrs.Exclude; import org.wso2.carbon.device.application.mgt.common.jaxrs.Exclude;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
/** /**
* This class holds the details when releasing an Application to application store. * This class holds the details when releasing an Application to application store.
@ -78,28 +76,26 @@ public class ApplicationRelease {
private String metaData; private String metaData;
private int noOfRatedUsers; private int ratedUsers;
private int stars; private Double rating;
private String url; private String url;
private boolean isPublishedRelease; public int getRatedUsers() {
return ratedUsers;
public int getNoOfRatedUsers() {
return noOfRatedUsers;
} }
public void setNoOfRatedUsers(int noOfRatedUsers) { public void setRatedUsers(int ratedUsers) {
this.noOfRatedUsers = noOfRatedUsers; this.ratedUsers = ratedUsers;
} }
public int getStars() { public Double getRating() {
return stars; return rating;
} }
public void setStars(int stars) { public void setRating(Double rating) {
this.stars = stars; this.rating = rating;
} }
public void setId(int id) { public void setId(int id) {
@ -302,11 +298,4 @@ public class ApplicationRelease {
this.url = url; this.url = url;
} }
public boolean isPublishedRelease() {
return isPublishedRelease;
}
public void setPublishedRelease(boolean publishedRelease) {
isPublishedRelease = publishedRelease;
}
} }

@ -1,137 +0,0 @@
/*
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
* WSO2 Inc. 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.wso2.carbon.device.application.mgt.common;
import java.util.Date;
import java.util.List;
/**
* Represents an lifecycle of an {@link Application}.
*/
public class Lifecycle {
private int id;
private Date createdAt;
private String createdBy;
private int isApproved;
private String approvedBy;
private Date approvedAt;
private int isPublished;
private String publishedBy;
private Date publishedAt;
private int isRetired;
private List<LifecycleStateTransition> lifecycleStateTransition;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public Date getCreatedAt() {
return createdAt;
}
public void setCreatedAt(Date createdAt) {
this.createdAt = createdAt;
}
public String getCreatedBy() {
return createdBy;
}
public void setCreatedBy(String createdBy) {
this.createdBy = createdBy;
}
public int getIsApproved() {
return isApproved;
}
public void setIsApproved(int isApproved) {
this.isApproved = isApproved;
}
public String getApprovedBy() {
return approvedBy;
}
public void setApprovedBy(String approvedBy) {
this.approvedBy = approvedBy;
}
public Date getApprovedAt() {
return approvedAt;
}
public void setApprovedAt(Date approvedAt) {
this.approvedAt = approvedAt;
}
public int getIsPublished() {
return isPublished;
}
public void setIsPublished(int isPublished) {
this.isPublished = isPublished;
}
public String getPublishedBy() {
return publishedBy;
}
public void setPublishedBy(String publishedBy) {
this.publishedBy = publishedBy;
}
public Date getPublishedAt() {
return publishedAt;
}
public void setPublishedAt(Date publishedAt) {
this.publishedAt = publishedAt;
}
public int getIsRetired() {
return isRetired;
}
public void setIsRetired(int isRetired) {
this.isRetired = isRetired;
}
public List<LifecycleStateTransition> getLifecycleStateTransition() {
return lifecycleStateTransition;
}
public void setLifecycleStateTransition(List<LifecycleStateTransition> lifecycleStateTransition) {
this.lifecycleStateTransition = lifecycleStateTransition;
}
}

@ -53,7 +53,7 @@ public interface ApplicationDAO {
* @param tenantId tenantId that need to identify application. * @param tenantId tenantId that need to identify application.
* @throws ApplicationManagementDAOException Application Management DAO Exception. * @throws ApplicationManagementDAOException Application Management DAO Exception.
*/ */
int isExistApplication(String appName, String type, int tenantId) throws ApplicationManagementDAOException; boolean isExistApplication(String appName, String type, int tenantId) throws ApplicationManagementDAOException;
/** /**
* To get the applications that satisfy the given criteria. * To get the applications that satisfy the given criteria.

@ -42,11 +42,11 @@ import java.util.List;
* @param createdBy Username of the created person. * @param createdBy Username of the created person.
* @param parentId parent id of the parent comment. * @param parentId parent id of the parent comment.
* @param uuid uuid of the application * @param uuid uuid of the application
* @return Comment Id * @return If comment is added successfully, it return true otherwise false
* @throws CommentManagementException Exceptions of the comment management. * @throws CommentManagementException Exceptions of the comment management.
* @throws DBConnectionException db connection exception. * @throws DBConnectionException db connection exception.
*/ */
int addComment(int tenantId, Comment comment, String createdBy, int parentId, String uuid) boolean addComment(int tenantId, Comment comment, String createdBy, int parentId, String uuid)
throws CommentManagementException, DBConnectionException, SQLException; throws CommentManagementException, DBConnectionException, SQLException;
/** /**

@ -171,7 +171,7 @@ public class Util {
appRelease.setCreatedAt(rs.getTimestamp("CREATED_AT")); appRelease.setCreatedAt(rs.getTimestamp("CREATED_AT"));
appRelease.setPublishedBy(rs.getString("PUBLISHED_BY")); appRelease.setPublishedBy(rs.getString("PUBLISHED_BY"));
appRelease.setPublishedAt(rs.getTimestamp("PUBLISHED_AT")); appRelease.setPublishedAt(rs.getTimestamp("PUBLISHED_AT"));
appRelease.setStars(rs.getInt("STARS")); appRelease.setRating(rs.getInt("STARS"));
appRelease.setIsSharedWithAllTenants(rs.getInt("SHARED_WITH_ALL_TENANTS")); appRelease.setIsSharedWithAllTenants(rs.getInt("SHARED_WITH_ALL_TENANTS"));
appRelease.setMetaData(rs.getString("APP_META_INFO")); appRelease.setMetaData(rs.getString("APP_META_INFO"));
appRelease.setScreenshotLoc1(rs.getString("SC_1_LOCATION")); appRelease.setScreenshotLoc1(rs.getString("SC_1_LOCATION"));

@ -46,10 +46,10 @@ import java.util.List;
public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO {
private static final Log log = LogFactory.getLog(CommentDAOImpl.class); private static final Log log = LogFactory.getLog(CommentDAOImpl.class);
String sql; private String sql;
@Override @Override
public int addComment(int tenantId, Comment comment, String createdBy, int parentId, String uuid) public boolean addComment(int tenantId, Comment comment, String createdBy, int parentId, String uuid)
throws CommentManagementException, DBConnectionException, SQLException { throws CommentManagementException, DBConnectionException, SQLException {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
@ -58,7 +58,6 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO {
Connection conn = this.getDBConnection(); Connection conn = this.getDBConnection();
PreparedStatement statement = null; PreparedStatement statement = null;
ResultSet rs = null; ResultSet rs = null;
int commentId = -1;
sql = "INSERT INTO AP_APP_COMMENT (TENANT_ID, COMMENT_TEXT, CREATED_BY, PARENT_ID,AP_APP_RELEASE_ID," sql = "INSERT INTO AP_APP_COMMENT (TENANT_ID, COMMENT_TEXT, CREATED_BY, PARENT_ID,AP_APP_RELEASE_ID,"
+ "AP_APP_ID) VALUES (?,?,?,?,(SELECT ID FROM AP_APP_RELEASE WHERE UUID= ?)," + "AP_APP_ID) VALUES (?,?,?,?,(SELECT ID FROM AP_APP_RELEASE WHERE UUID= ?),"
+ "(SELECT AP_APP_ID FROM AP_APP_RELEASE WHERE UUID=?));"; + "(SELECT AP_APP_ID FROM AP_APP_RELEASE WHERE UUID=?));";
@ -72,10 +71,7 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO {
statement.setString(6, uuid); statement.setString(6, uuid);
statement.executeUpdate(); statement.executeUpdate();
rs = statement.getGeneratedKeys(); rs = statement.getGeneratedKeys();
if (rs.next()) { return rs.next();
commentId = rs.getInt(1);
}
return commentId;
} finally { } finally {
Util.cleanupResources(statement, rs); Util.cleanupResources(statement, rs);
} }
@ -924,7 +920,7 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO {
int numORows = resultSet.getRow(); int numORows = resultSet.getRow();
if (resultSet.next()) { if (resultSet.next()) {
ApplicationRelease applicationRelease = new ApplicationRelease(); ApplicationRelease applicationRelease = new ApplicationRelease();
applicationRelease.setStars(resultSet.getInt("STARS")); applicationRelease.setRating(resultSet.getDouble("RATING"));
Util.cleanupResources(statement, resultSet); Util.cleanupResources(statement, resultSet);
} }
} catch (SQLException e) { } catch (SQLException e) {
@ -987,7 +983,7 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO {
if (resultSet.next()) { if (resultSet.next()) {
ApplicationRelease applicationRelease = new ApplicationRelease(); ApplicationRelease applicationRelease = new ApplicationRelease();
ratedUsers = resultSet.getInt("NO_OF_RATED_USERS"); ratedUsers = resultSet.getInt("NO_OF_RATED_USERS");
applicationRelease.setNoOfRatedUsers(ratedUsers); applicationRelease.setRatedUsers(ratedUsers);
Util.cleanupResources(statement, resultSet); Util.cleanupResources(statement, resultSet);
return ratedUsers; return ratedUsers;
} }

@ -94,14 +94,13 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
} }
@Override @Override
public int isExistApplication(String appName, String type, int tenantId) throws ApplicationManagementDAOException { public boolean isExistApplication(String appName, String type, int tenantId) throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to verify whether the registering app is registered or not"); log.debug("Request received in DAO Layer to verify whether the registering app is registered or not");
} }
Connection conn; Connection conn;
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
int isExist = 0;
String sql = "SELECT * FROM AP_APP WHERE NAME = ? AND TYPE = ? AND TENANT_ID = ?"; String sql = "SELECT * FROM AP_APP WHERE NAME = ? AND TYPE = ? AND TENANT_ID = ?";
try { try {
conn = this.getDBConnection(); conn = this.getDBConnection();
@ -111,11 +110,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
stmt.setString(2, type); stmt.setString(2, type);
stmt.setInt(3, tenantId); stmt.setInt(3, tenantId);
rs = stmt.executeQuery(); rs = stmt.executeQuery();
if (rs.next()) { return rs.next();
isExist = 1;
}
return isExist;
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new ApplicationManagementDAOException( throw new ApplicationManagementDAOException(

@ -112,7 +112,6 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
Connection connection; Connection connection;
PreparedStatement statement = null; PreparedStatement statement = null;
ResultSet resultSet = null; ResultSet resultSet = null;
ApplicationRelease applicationRelease = null;
String sql = "SELECT AR.ID AS RELESE_ID, AR.VERSION AS RELEASE_VERSION, AR.UUID, AR.RELEASE_TYPE, AR.APP_PRICE," String sql = "SELECT AR.ID AS RELESE_ID, AR.VERSION AS RELEASE_VERSION, AR.UUID, AR.RELEASE_TYPE, AR.APP_PRICE,"
+ " AR.STORED_LOCATION, AR.BANNER_LOCATION, AR.SC_1_LOCATION AS SCREEN_SHOT_1, " + " AR.STORED_LOCATION, AR.BANNER_LOCATION, AR.SC_1_LOCATION AS SCREEN_SHOT_1, "
+ "AR.SC_2_LOCATION AS SCREEN_SHOT_2, AR.SC_3_LOCATION AS SCREEN_SHOT_3, AR.APP_HASH_VALUE AS HASH_VALUE, " + "AR.SC_2_LOCATION AS SCREEN_SHOT_2, AR.SC_3_LOCATION AS SCREEN_SHOT_3, AR.APP_HASH_VALUE AS HASH_VALUE, "
@ -134,31 +133,9 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
resultSet = statement.executeQuery(); resultSet = statement.executeQuery();
if (resultSet.next()) { if (resultSet.next()) {
applicationRelease = new ApplicationRelease(); return constructApplicationRelease(resultSet);
applicationRelease.setId(resultSet.getInt("RELEASE_ID"));
applicationRelease.setVersion(resultSet.getString("RELEASE_VERSION"));
applicationRelease.setUuid(resultSet.getString("UUID"));
applicationRelease.setReleaseType(resultSet.getString("RELEASE_TYPE"));
applicationRelease.setPrice(resultSet.getDouble("APP_PRICE"));
applicationRelease.setAppStoredLoc(resultSet.getString("STORED_LOCATION"));
applicationRelease.setBannerLoc(resultSet.getString("BANNER_LOCATION"));
applicationRelease.setScreenshotLoc1(resultSet.getString("SCREEN_SHOT_1"));
applicationRelease.setScreenshotLoc2(resultSet.getString("SCREEN_SHOT_2"));
applicationRelease.setScreenshotLoc3(resultSet.getString("SCREEN_SHOT_3"));
applicationRelease.setAppHashValue(resultSet.getString("HASH_VALUE"));
applicationRelease.setIsSharedWithAllTenants(resultSet.getInt("SHARED"));
applicationRelease.setMetaData(resultSet.getString("APP_META_INFO"));
applicationRelease.setApplicationCreator(resultSet.getString("CREATED_BY"));
applicationRelease.setCreatedAt(resultSet.getTimestamp("CREATED_AT"));
applicationRelease.setPublishedBy(resultSet.getString("PUBLISHED_BY"));
applicationRelease.setPublishedAt(resultSet.getTimestamp("PUBLISHED_AT"));
applicationRelease.setStars(resultSet.getInt("STARS"));
applicationRelease.setCurrentState(resultSet.getString("CURRENT_STATE"));
applicationRelease.setPreviousState(resultSet.getString("PREVIOUSE_STATE"));
applicationRelease.setStateModifiedBy(resultSet.getString("UPDATED_BY"));
applicationRelease.setStateModifiedAt(resultSet.getTimestamp("UPDATED_AT"));
} }
return applicationRelease; return null;
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new ApplicationManagementDAOException("Database connection exception while trying to get the " throw new ApplicationManagementDAOException("Database connection exception while trying to get the "
+ "release details of the application with " + applicationName + " and version " + + "release details of the application with " + applicationName + " and version " +
@ -186,7 +163,6 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
Connection connection; Connection connection;
PreparedStatement statement = null; PreparedStatement statement = null;
ResultSet resultSet = null; ResultSet resultSet = null;
ApplicationRelease applicationRelease = null;
String sql = "SELECT AR.ID AS RELESE_ID, AR.VERSION AS RELEASE_VERSION, AR.UUID, AR.RELEASE_TYPE, AR.APP_PRICE," String sql = "SELECT AR.ID AS RELESE_ID, AR.VERSION AS RELEASE_VERSION, AR.UUID, AR.RELEASE_TYPE, AR.APP_PRICE,"
+ " AR.STORED_LOCATION, AR.BANNER_LOCATION, AR.SC_1_LOCATION AS SCREEN_SHOT_1, " + " AR.STORED_LOCATION, AR.BANNER_LOCATION, AR.SC_1_LOCATION AS SCREEN_SHOT_1, "
+ "AR.SC_2_LOCATION AS SCREEN_SHOT_2, AR.SC_3_LOCATION AS SCREEN_SHOT_3, AR.APP_HASH_VALUE AS " + + "AR.SC_2_LOCATION AS SCREEN_SHOT_2, AR.SC_3_LOCATION AS SCREEN_SHOT_3, AR.APP_HASH_VALUE AS " +
@ -205,31 +181,9 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
resultSet = statement.executeQuery(); resultSet = statement.executeQuery();
if (resultSet.next()) { if (resultSet.next()) {
applicationRelease = new ApplicationRelease(); return constructApplicationRelease(resultSet);
applicationRelease.setId(resultSet.getInt("RELEASE_ID"));
applicationRelease.setVersion(resultSet.getString("RELEASE_VERSION"));
applicationRelease.setUuid(resultSet.getString("UUID"));
applicationRelease.setReleaseType(resultSet.getString("RELEASE_TYPE"));
applicationRelease.setPrice(resultSet.getDouble("APP_PRICE"));
applicationRelease.setAppStoredLoc(resultSet.getString("STORED_LOCATION"));
applicationRelease.setBannerLoc(resultSet.getString("BANNER_LOCATION"));
applicationRelease.setScreenshotLoc1(resultSet.getString("SCREEN_SHOT_1"));
applicationRelease.setScreenshotLoc2(resultSet.getString("SCREEN_SHOT_2"));
applicationRelease.setScreenshotLoc3(resultSet.getString("SCREEN_SHOT_3"));
applicationRelease.setAppHashValue(resultSet.getString("HASH_VALUE"));
applicationRelease.setIsSharedWithAllTenants(resultSet.getInt("SHARED"));
applicationRelease.setMetaData(resultSet.getString("APP_META_INFO"));
applicationRelease.setApplicationCreator(resultSet.getString("CREATED_BY"));
applicationRelease.setCreatedAt(resultSet.getTimestamp("CREATED_AT"));
applicationRelease.setPublishedBy(resultSet.getString("PUBLISHED_BY"));
applicationRelease.setPublishedAt(resultSet.getTimestamp("PUBLISHED_AT"));
applicationRelease.setStars(resultSet.getInt("STARS"));
applicationRelease.setCurrentState(resultSet.getString("CURRENT_STATE"));
applicationRelease.setPreviousState(resultSet.getString("PREVIOUSE_STATE"));
applicationRelease.setStateModifiedBy(resultSet.getString("UPDATED_BY"));
applicationRelease.setStateModifiedAt(resultSet.getTimestamp("UPDATED_AT"));
} }
return applicationRelease; return null;
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new ApplicationManagementDAOException( throw new ApplicationManagementDAOException(
"Database connection exception while trying to get the release details of the " + "Database connection exception while trying to get the release details of the " +
@ -296,7 +250,7 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
applicationRelease.setCreatedAt(resultSet.getTimestamp("CREATED_AT")); applicationRelease.setCreatedAt(resultSet.getTimestamp("CREATED_AT"));
applicationRelease.setPublishedBy(resultSet.getString("PUBLISHED_BY")); applicationRelease.setPublishedBy(resultSet.getString("PUBLISHED_BY"));
applicationRelease.setPublishedAt(resultSet.getTimestamp("PUBLISHED_AT")); applicationRelease.setPublishedAt(resultSet.getTimestamp("PUBLISHED_AT"));
applicationRelease.setStars(resultSet.getInt("STARS")); applicationRelease.setRating(resultSet.getDouble("RATING"));
applicationReleases.add(applicationRelease); applicationReleases.add(applicationRelease);
} }
@ -417,4 +371,37 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
} }
} }
/**
* This method is capable to construct {@ApplicationRelease} and return the object
* @param resultSet result set obtained from the query executing.
* @throws SQLException SQL exception while accessing result set data.
*/
private ApplicationRelease constructApplicationRelease(ResultSet resultSet) throws SQLException {
ApplicationRelease applicationRelease = new ApplicationRelease();
applicationRelease.setId(resultSet.getInt("RELEASE_ID"));
applicationRelease.setVersion(resultSet.getString("RELEASE_VERSION"));
applicationRelease.setUuid(resultSet.getString("UUID"));
applicationRelease.setReleaseType(resultSet.getString("RELEASE_TYPE"));
applicationRelease.setPrice(resultSet.getDouble("APP_PRICE"));
applicationRelease.setAppStoredLoc(resultSet.getString("STORED_LOCATION"));
applicationRelease.setBannerLoc(resultSet.getString("BANNER_LOCATION"));
applicationRelease.setScreenshotLoc1(resultSet.getString("SCREEN_SHOT_1"));
applicationRelease.setScreenshotLoc2(resultSet.getString("SCREEN_SHOT_2"));
applicationRelease.setScreenshotLoc3(resultSet.getString("SCREEN_SHOT_3"));
applicationRelease.setAppHashValue(resultSet.getString("HASH_VALUE"));
applicationRelease.setIsSharedWithAllTenants(resultSet.getInt("SHARED"));
applicationRelease.setMetaData(resultSet.getString("APP_META_INFO"));
applicationRelease.setApplicationCreator(resultSet.getString("CREATED_BY"));
applicationRelease.setCreatedAt(resultSet.getTimestamp("CREATED_AT"));
applicationRelease.setPublishedBy(resultSet.getString("PUBLISHED_BY"));
applicationRelease.setPublishedAt(resultSet.getTimestamp("PUBLISHED_AT"));
applicationRelease.setRating(resultSet.getDouble("RATING"));
applicationRelease.setCurrentState(resultSet.getString("CURRENT_STATE"));
applicationRelease.setPreviousState(resultSet.getString("PREVIOUS_STATE"));
applicationRelease.setStateModifiedBy(resultSet.getString("UPDATED_BY"));
applicationRelease.setStateModifiedAt(resultSet.getTimestamp("UPDATED_AT"));
return applicationRelease;
}
} }

@ -99,6 +99,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
ApplicationRelease applicationRelease; ApplicationRelease applicationRelease;
try { try {
ConnectionManagerUtil.beginDBTransaction(); ConnectionManagerUtil.beginDBTransaction();
// todo think about web clip and try to remove application - type
deviceType = this.deviceTypeDAO.getDeviceType(application.getType(), tenantId); deviceType = this.deviceTypeDAO.getDeviceType(application.getType(), tenantId);
if (deviceType == null) { if (deviceType == null) {
@ -351,12 +352,12 @@ public class ApplicationManagerImpl implements ApplicationManager {
applicationReleases = ApplicationManagementDAOFactory.getApplicationReleaseDAO() applicationReleases = ApplicationManagementDAOFactory.getApplicationReleaseDAO()
.getReleases(application.getName(), application.getType(), tenantId); .getReleases(application.getName(), application.getType(), tenantId);
for (ApplicationRelease applicationRelease : applicationReleases) { for (ApplicationRelease applicationRelease : applicationReleases) {
if (AppLifecycleState.PUBLISHED.toString().equals(ApplicationManagementDAOFactory.getLifecycleStateDAO(). LifecycleState lifecycleState = ApplicationManagementDAOFactory.getLifecycleStateDAO().
getLatestLifeCycleStateByReleaseID(applicationRelease.getId()).getCurrentState())){ getLatestLifeCycleStateByReleaseID(applicationRelease.getId());
applicationRelease.setPublishedRelease(true); applicationRelease.setCurrentState(lifecycleState.getCurrentState());
} applicationRelease.setPreviousState(lifecycleState.getPreviousState());
if (!AppLifecycleState.REMOVED.toString().equals(ApplicationManagementDAOFactory.getLifecycleStateDAO().
getLatestLifeCycleStateByReleaseID(applicationRelease.getId()).getCurrentState())) { if (!AppLifecycleState.REMOVED.toString().equals(applicationRelease.getCurrentState())) {
filteredApplicationReleases.add(applicationRelease); filteredApplicationReleases.add(applicationRelease);
} }
} }

@ -65,9 +65,13 @@ public class CommentsManagerImpl implements CommentsManager {
comment.setCreatedAt(Timestamp.from(Instant.now())); comment.setCreatedAt(Timestamp.from(Instant.now()));
try { try {
ConnectionManagerUtil.beginDBTransaction(); ConnectionManagerUtil.beginDBTransaction();
commentDAO.addComment(tenantId, comment, comment.getCreatedBy(), comment.getParent(), uuid); if (commentDAO.addComment(tenantId, comment, comment.getCreatedBy(), comment.getParent(), uuid)) {
ConnectionManagerUtil.commitDBTransaction(); ConnectionManagerUtil.commitDBTransaction();
return comment; return comment;
} else {
ConnectionManagerUtil.rollbackDBTransaction();
return null;
}
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
ConnectionManagerUtil.rollbackDBTransaction(); ConnectionManagerUtil.rollbackDBTransaction();
throw new CommentManagementException( throw new CommentManagementException(

@ -96,12 +96,12 @@ import java.util.List;
} }
) )
@Path("/comments") @Path("/reviews")
@Api(value = "Comments Management", description = "This API carries all comments management related operations " + @Api(value = "Comments Management", description = "This API carries all comments management related operations " +
"such as get all the comments, add comment, etc.") "such as get all the comments, add comment, etc.")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
public interface CommentManagementAPI { public interface ReviewManagementAPI {
String SCOPE = "scope"; String SCOPE = "scope";
@GET @GET
@ -191,7 +191,7 @@ public interface CommentManagementAPI {
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
Response addComments( Response addComment(
@ApiParam( @ApiParam(
name = "comment", name = "comment",
value = "Comment details", value = "Comment details",
@ -322,7 +322,7 @@ public interface CommentManagementAPI {
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
Response getStars( Response getRating(
@ApiParam( @ApiParam(
name = "uuid", name = "uuid",
value = "uuid of the application release", value = "uuid of the application release",
@ -359,7 +359,7 @@ public interface CommentManagementAPI {
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
Response getRatedUser( Response getNumOfRatedUsers(
@ApiParam( @ApiParam(
name = "uuid", name = "uuid",
value = "uuid of the application release", value = "uuid of the application release",
@ -401,7 +401,7 @@ public interface CommentManagementAPI {
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
Response updateStars( Response updateRatings(
@ApiParam( @ApiParam(
name = "stars", name = "stars",
value = "ratings for the application", value = "ratings for the application",

@ -20,6 +20,7 @@ package org.wso2.carbon.device.application.mgt.store.api.services.impl;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.application.mgt.common.AppLifecycleState;
import org.wso2.carbon.device.application.mgt.common.ApplicationRelease; import org.wso2.carbon.device.application.mgt.common.ApplicationRelease;
import org.wso2.carbon.device.application.mgt.store.api.APIUtil; import org.wso2.carbon.device.application.mgt.store.api.APIUtil;
import org.wso2.carbon.device.application.mgt.common.Application; import org.wso2.carbon.device.application.mgt.common.Application;
@ -48,7 +49,6 @@ import java.util.List;
@Path("/store/applications") @Path("/store/applications")
public class ApplicationManagementAPIImpl implements ApplicationManagementAPI { public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
private static final int DEFAULT_LIMIT = 20;
private static Log log = LogFactory.getLog(ApplicationManagementAPIImpl.class); private static Log log = LogFactory.getLog(ApplicationManagementAPIImpl.class);
@GET @GET
@ -70,7 +70,7 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
for (Application application : applications.getApplications()) { for (Application application : applications.getApplications()) {
for (ApplicationRelease appRelease: application.getApplicationReleases()){ for (ApplicationRelease appRelease: application.getApplicationReleases()){
if (appRelease.isPublishedRelease()){ if (AppLifecycleState.PUBLISHED.toString().equals(appRelease.getCurrentState())){
publishedApplicationRelease.add(appRelease); publishedApplicationRelease.add(appRelease);
} }
} }
@ -110,7 +110,7 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
} }
for (ApplicationRelease appRelease : application.getApplicationReleases()) { for (ApplicationRelease appRelease : application.getApplicationReleases()) {
if (appRelease.isPublishedRelease()) { if (AppLifecycleState.PUBLISHED.toString().equals(appRelease.getCurrentState())){
publishedApplicationRelease.add(appRelease); publishedApplicationRelease.add(appRelease);
} }
} }

@ -22,7 +22,7 @@ import io.swagger.annotations.ApiParam;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.application.mgt.store.api.APIUtil; import org.wso2.carbon.device.application.mgt.store.api.APIUtil;
import org.wso2.carbon.device.application.mgt.store.api.services.CommentManagementAPI; import org.wso2.carbon.device.application.mgt.store.api.services.ReviewManagementAPI;
import org.wso2.carbon.device.application.mgt.common.Comment; import org.wso2.carbon.device.application.mgt.common.Comment;
import org.wso2.carbon.device.application.mgt.common.PaginationRequest; import org.wso2.carbon.device.application.mgt.common.PaginationRequest;
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException; import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException;
@ -44,18 +44,18 @@ import java.util.List;
/** /**
* Comment Management related jax-rs APIs. * Comment Management related jax-rs APIs.
*/ */
@Path("/comments") @Path("/review")
public class CommentManagementAPIImpl implements CommentManagementAPI { public class ReviewManagementAPIImpl implements ReviewManagementAPI {
private static Log log = LogFactory.getLog(CommentManagementAPIImpl.class); private static Log log = LogFactory.getLog(ReviewManagementAPIImpl.class);
@Override @Override
@GET @GET
@Path("/{uuid}") @Path("/application/{uuid}/comments")
public Response getAllComments( public Response getAllComments(
@PathParam("uuid") String uuid, @PathParam("uuid") String uuid,
@QueryParam("offset") int offSet, @ @QueryParam("offset") int offSet,
QueryParam("limit") int limit) { @QueryParam("limit") int limit) {
CommentsManager commentsManager = APIUtil.getCommentsManager(); CommentsManager commentsManager = APIUtil.getCommentsManager();
List<Comment> comments = new ArrayList<>(); List<Comment> comments = new ArrayList<>();
@ -79,16 +79,15 @@ public class CommentManagementAPIImpl implements CommentManagementAPI {
@Override @Override
@POST @POST
@Consumes("application/json") @Consumes("application/json")
@Path("/{uuid}") @Path("/application/{uuid}/comment")
public Response addComments( public Response addComment(
@ApiParam Comment comment, @ApiParam Comment comment,
@PathParam("uuid") String uuid) { @PathParam("uuid") String uuid) {
CommentsManager commentsManager = APIUtil.getCommentsManager(); CommentsManager commentsManager = APIUtil.getCommentsManager();
try { try {
Comment newComment = commentsManager.addComment(comment, uuid); if (commentsManager.addComment(comment, uuid) != null) {
if (comment != null) { return Response.status(Response.Status.CREATED).entity(comment).build();
return Response.status(Response.Status.CREATED).entity(newComment).build();
} else { } else {
String msg = "Given comment is not valid "; String msg = "Given comment is not valid ";
log.error(msg); log.error(msg);
@ -105,7 +104,7 @@ public class CommentManagementAPIImpl implements CommentManagementAPI {
@Override @Override
@PUT @PUT
@Consumes("application/json") @Consumes("application/json")
@Path("/{commentId}") @Path("/comment/{commentId}")
public Response updateComment( public Response updateComment(
@ApiParam Comment comment, @ApiParam Comment comment,
@PathParam("commentId") int commentId) { @PathParam("commentId") int commentId) {
@ -133,7 +132,7 @@ public class CommentManagementAPIImpl implements CommentManagementAPI {
@Override @Override
@DELETE @DELETE
@Path("/{commentId}") @Path("/comment/{commentId}")
public Response deleteComment( public Response deleteComment(
@PathParam("commentId") int commentId) { @PathParam("commentId") int commentId) {
@ -155,14 +154,14 @@ public class CommentManagementAPIImpl implements CommentManagementAPI {
@Override @Override
@GET @GET
@Path("/{uuid}") @Path("/application/{uuid}/rating")
public Response getStars( public Response getRating(
@PathParam("uuid") String uuid) { @PathParam("uuid") String uuid) {
CommentsManager commentsManager = APIUtil.getCommentsManager(); CommentsManager commentsManager = APIUtil.getCommentsManager();
int Stars; int stars;
try { try {
Stars = commentsManager.getStars(uuid); stars = commentsManager.getStars(uuid);
} catch (CommentManagementException e) { } catch (CommentManagementException e) {
log.error("Comment Management Exception occurs", e); log.error("Comment Management Exception occurs", e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
@ -172,13 +171,13 @@ public class CommentManagementAPIImpl implements CommentManagementAPI {
return Response.status(Response.Status.INTERNAL_SERVER_ERROR) return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
.entity(msg).build(); .entity(msg).build();
} }
return Response.status(Response.Status.OK).entity(Stars).build(); return Response.status(Response.Status.OK).entity(stars).build();
} }
@Override @Override
@GET @GET
@Path("/{uuid}") @Path("/application/{uuid}/total-rated-users")
public Response getRatedUser( public Response getNumOfRatedUsers(
@PathParam("uuid") String uuid) { @PathParam("uuid") String uuid) {
CommentsManager commentsManager = APIUtil.getCommentsManager(); CommentsManager commentsManager = APIUtil.getCommentsManager();
@ -200,9 +199,10 @@ public class CommentManagementAPIImpl implements CommentManagementAPI {
} }
@Override @Override
@POST @PUT
@Consumes("application/json") @Consumes("application/json")
public Response updateStars( @Path("/application/{uuid}/rating")
public Response updateRatings(
@ApiParam int stars, @ApiParam int stars,
@PathParam("uuid") String uuid) { @PathParam("uuid") String uuid) {

@ -35,7 +35,7 @@ import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManage
import org.wso2.carbon.device.application.mgt.common.exception.CommentManagementException; import org.wso2.carbon.device.application.mgt.common.exception.CommentManagementException;
import org.wso2.carbon.device.application.mgt.common.services.CommentsManager; import org.wso2.carbon.device.application.mgt.common.services.CommentsManager;
import org.wso2.carbon.device.application.mgt.store.api.APIUtil; import org.wso2.carbon.device.application.mgt.store.api.APIUtil;
import org.wso2.carbon.device.application.mgt.store.api.services.impl.CommentManagementAPIImpl; import org.wso2.carbon.device.application.mgt.store.api.services.impl.ReviewManagementAPIImpl;
import org.wso2.carbon.device.application.mgt.store.api.services.util.CommentMgtTestHelper; import org.wso2.carbon.device.application.mgt.store.api.services.util.CommentMgtTestHelper;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
@ -48,9 +48,9 @@ import static org.mockito.MockitoAnnotations.initMocks;
@PrepareForTest({ APIUtil.class, CommentsManager.class, @PrepareForTest({ APIUtil.class, CommentsManager.class,
CommentManagementAPITest.class}) CommentManagementAPITest.class})
public class CommentManagementAPITest { public class CommentManagementAPITest {
private static final Log log = LogFactory.getLog(CommentManagementAPI.class); private static final Log log = LogFactory.getLog(ReviewManagementAPI.class);
private CommentManagementAPI commentManagementAPI; private ReviewManagementAPI commentManagementAPI;
private CommentsManager commentsManager; private CommentsManager commentsManager;
@ObjectFactory @ObjectFactory
@ -61,10 +61,10 @@ public class CommentManagementAPITest {
@BeforeClass @BeforeClass
void init() throws CommentManagementException { void init() throws CommentManagementException {
log.info("Initializing CommentManagementAPI tests"); log.info("Initializing ReviewManagementAPI tests");
initMocks(this); initMocks(this);
this.commentsManager = Mockito.mock(CommentsManager.class, Mockito.RETURNS_DEFAULTS); this.commentsManager = Mockito.mock(CommentsManager.class, Mockito.RETURNS_DEFAULTS);
this.commentManagementAPI = new CommentManagementAPIImpl(); this.commentManagementAPI = new ReviewManagementAPIImpl();
} }
@Test @Test
@ -103,7 +103,7 @@ public class CommentManagementAPITest {
public void testAddComments() throws Exception { public void testAddComments() throws Exception {
Comment comment = CommentMgtTestHelper.getDummyComment("a", "a"); Comment comment = CommentMgtTestHelper.getDummyComment("a", "a");
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getCommentsManager")).toReturn(this.commentsManager); PowerMockito.stub(PowerMockito.method(APIUtil.class, "getCommentsManager")).toReturn(this.commentsManager);
Response response = this.commentManagementAPI.addComments(comment, "a"); Response response = this.commentManagementAPI.addComment(comment, "a");
Assert.assertNotNull(response, "The response object is null."); Assert.assertNotNull(response, "The response object is null.");
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode(), Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode(),
"The response status should be 201."); "The response status should be 201.");
@ -113,7 +113,7 @@ public class CommentManagementAPITest {
@Test @Test
public void testAddNullComment() throws Exception { public void testAddNullComment() throws Exception {
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getCommentsManager")).toReturn(this.commentsManager); PowerMockito.stub(PowerMockito.method(APIUtil.class, "getCommentsManager")).toReturn(this.commentsManager);
Response response = this.commentManagementAPI.addComments(null, "a"); Response response = this.commentManagementAPI.addComment(null, "a");
Assert.assertNotNull(response, "The response object is null."); Assert.assertNotNull(response, "The response object is null.");
Assert.assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode(), Assert.assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode(),
"The response status should be 400."); "The response status should be 400.");
@ -124,9 +124,9 @@ public class CommentManagementAPITest {
public void testAddCommentsInternalError() throws Exception { public void testAddCommentsInternalError() throws Exception {
Comment comment = CommentMgtTestHelper.getDummyComment("a", "a"); Comment comment = CommentMgtTestHelper.getDummyComment("a", "a");
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getCommentsManager")).toReturn(this.commentsManager); PowerMockito.stub(PowerMockito.method(APIUtil.class, "getCommentsManager")).toReturn(this.commentsManager);
Mockito.when(this.commentManagementAPI.addComments(Mockito.any(), Mockito.anyString())) Mockito.when(this.commentManagementAPI.addComment(Mockito.any(), Mockito.anyString()))
.thenThrow(new CommentManagementException()); .thenThrow(new CommentManagementException());
Response response = this.commentManagementAPI.addComments(comment, null); Response response = this.commentManagementAPI.addComment(comment, null);
Assert.assertNotNull(response, "The response object is null."); Assert.assertNotNull(response, "The response object is null.");
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
"The response status should be 500."); "The response status should be 500.");
@ -204,7 +204,7 @@ public class CommentManagementAPITest {
@Test @Test
public void testGetStars() throws Exception { public void testGetStars() throws Exception {
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getCommentsManager")).toReturn(this.commentsManager); PowerMockito.stub(PowerMockito.method(APIUtil.class, "getCommentsManager")).toReturn(this.commentsManager);
Response response = this.commentManagementAPI.getStars("a"); Response response = this.commentManagementAPI.getRating("a");
Assert.assertNotNull(response, "The response object is null."); Assert.assertNotNull(response, "The response object is null.");
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(), Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(),
"The response status should be 200."); "The response status should be 200.");
@ -214,9 +214,9 @@ public class CommentManagementAPITest {
@Test @Test
public void testGetStarsCommentError() throws Exception { public void testGetStarsCommentError() throws Exception {
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getCommentsManager")).toReturn(this.commentsManager); PowerMockito.stub(PowerMockito.method(APIUtil.class, "getCommentsManager")).toReturn(this.commentsManager);
Mockito.when(this.commentManagementAPI.getStars(Mockito.anyString())) Mockito.when(this.commentManagementAPI.getRating(Mockito.anyString()))
.thenThrow(new CommentManagementException()); .thenThrow(new CommentManagementException());
Response response = this.commentManagementAPI.getStars("a"); Response response = this.commentManagementAPI.getRating("a");
Assert.assertNotNull(response, "The response object is null."); Assert.assertNotNull(response, "The response object is null.");
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
"The response status should be 500."); "The response status should be 500.");
@ -226,9 +226,9 @@ public class CommentManagementAPITest {
@Test @Test
public void testGetStarsApplicationError() throws Exception { public void testGetStarsApplicationError() throws Exception {
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getCommentsManager")).toReturn(this.commentsManager); PowerMockito.stub(PowerMockito.method(APIUtil.class, "getCommentsManager")).toReturn(this.commentsManager);
Mockito.when(this.commentManagementAPI.getStars(Mockito.anyString())) Mockito.when(this.commentManagementAPI.getRating(Mockito.anyString()))
.thenThrow(new ApplicationManagementException()); .thenThrow(new ApplicationManagementException());
Response response = this.commentManagementAPI.getStars("a"); Response response = this.commentManagementAPI.getRating("a");
Assert.assertNotNull(response, "The response object is null."); Assert.assertNotNull(response, "The response object is null.");
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
"The response status should be 500."); "The response status should be 500.");
@ -238,7 +238,7 @@ public class CommentManagementAPITest {
@Test @Test
public void testGetRatedUser() throws Exception { public void testGetRatedUser() throws Exception {
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getCommentsManager")).toReturn(this.commentsManager); PowerMockito.stub(PowerMockito.method(APIUtil.class, "getCommentsManager")).toReturn(this.commentsManager);
Response response = this.commentManagementAPI.getRatedUser("a"); Response response = this.commentManagementAPI.getNumOfRatedUsers("a");
Assert.assertNotNull(response, "The response object is null."); Assert.assertNotNull(response, "The response object is null.");
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(), Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(),
"The response status should be 200."); "The response status should be 200.");
@ -248,9 +248,9 @@ public class CommentManagementAPITest {
@Test @Test
public void testGetRatedUserCommentError() throws Exception { public void testGetRatedUserCommentError() throws Exception {
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getCommentsManager")).toReturn(this.commentsManager); PowerMockito.stub(PowerMockito.method(APIUtil.class, "getCommentsManager")).toReturn(this.commentsManager);
Mockito.when(this.commentManagementAPI.getRatedUser(Mockito.anyString())) Mockito.when(this.commentManagementAPI.getNumOfRatedUsers(Mockito.anyString()))
.thenThrow(new CommentManagementException()); .thenThrow(new CommentManagementException());
Response response = this.commentManagementAPI.getRatedUser("a"); Response response = this.commentManagementAPI.getNumOfRatedUsers("a");
Assert.assertNotNull(response, "The response object is null."); Assert.assertNotNull(response, "The response object is null.");
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
"The response status should be 500."); "The response status should be 500.");
@ -260,9 +260,9 @@ public class CommentManagementAPITest {
@Test @Test
public void testGetRatedUserApplicationError() throws Exception { public void testGetRatedUserApplicationError() throws Exception {
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getCommentsManager")).toReturn(this.commentsManager); PowerMockito.stub(PowerMockito.method(APIUtil.class, "getCommentsManager")).toReturn(this.commentsManager);
Mockito.when(this.commentManagementAPI.getRatedUser(Mockito.anyString())) Mockito.when(this.commentManagementAPI.getNumOfRatedUsers(Mockito.anyString()))
.thenThrow(new ApplicationManagementException()); .thenThrow(new ApplicationManagementException());
Response response = this.commentManagementAPI.getRatedUser("a"); Response response = this.commentManagementAPI.getNumOfRatedUsers("a");
Assert.assertNotNull(response, "The response object is null."); Assert.assertNotNull(response, "The response object is null.");
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
"The response status should be 500."); "The response status should be 500.");
@ -272,7 +272,7 @@ public class CommentManagementAPITest {
@Test @Test
public void testUpdateStars() throws Exception { public void testUpdateStars() throws Exception {
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getCommentsManager")).toReturn(this.commentsManager); PowerMockito.stub(PowerMockito.method(APIUtil.class, "getCommentsManager")).toReturn(this.commentsManager);
Response response = this.commentManagementAPI.updateStars(3, "a"); Response response = this.commentManagementAPI.updateRatings(3, "a");
Assert.assertNotNull(response, "The response object is null."); Assert.assertNotNull(response, "The response object is null.");
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode(), Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode(),
"The response status should be 201."); "The response status should be 201.");
@ -282,7 +282,7 @@ public class CommentManagementAPITest {
@Test @Test
public void testUpdateInvalidStars() throws Exception { public void testUpdateInvalidStars() throws Exception {
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getCommentsManager")).toReturn(this.commentsManager); PowerMockito.stub(PowerMockito.method(APIUtil.class, "getCommentsManager")).toReturn(this.commentsManager);
Response response = this.commentManagementAPI.updateStars(0, "a"); Response response = this.commentManagementAPI.updateRatings(0, "a");
Assert.assertNotNull(response, "The response object is null."); Assert.assertNotNull(response, "The response object is null.");
Assert.assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode(), Assert.assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode(),
"The response status should be 400."); "The response status should be 400.");
@ -294,7 +294,7 @@ public class CommentManagementAPITest {
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getCommentsManager")).toReturn(this.commentsManager); PowerMockito.stub(PowerMockito.method(APIUtil.class, "getCommentsManager")).toReturn(this.commentsManager);
Mockito.doThrow(new ApplicationManagementException()).when(this.commentsManager) Mockito.doThrow(new ApplicationManagementException()).when(this.commentsManager)
.updateStars(Mockito.anyInt(), Mockito.anyString()); .updateStars(Mockito.anyInt(), Mockito.anyString());
Response response = this.commentManagementAPI.updateStars(3, "a"); Response response = this.commentManagementAPI.updateRatings(3, "a");
Assert.assertNotNull(response, "The response object is null."); Assert.assertNotNull(response, "The response object is null.");
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
"The response status should be 500."); "The response status should be 500.");

Loading…
Cancel
Save