Skip to content

Commit

Permalink
Improve ApplicationTest.java code
Browse files Browse the repository at this point in the history
  • Loading branch information
hsluoyz committed Oct 12, 2023
1 parent 6256d04 commit c761a42
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 344 deletions.
319 changes: 0 additions & 319 deletions src/main/java/org/casbin/casdoor/entity/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@

package org.casbin.casdoor.entity;


import java.io.Serializable;
import java.util.List;


public class Application implements Serializable {
public String owner;
public String name;
Expand Down Expand Up @@ -63,9 +61,6 @@ public class Application implements Serializable {
public Application() {
}

/**
* create test constructor
*/
public Application(String owner, String name, String createdTime, String displayName, String logo, String homepageUrl, String description, String organization) {
this.owner = owner;
this.name = name;
Expand All @@ -76,318 +71,4 @@ public Application(String owner, String name, String createdTime, String display
this.description = description;
this.organization = organization;
}

public String getOwner() {
return owner;
}

public void setOwner(String owner) {
this.owner = owner;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getCreatedTime() {
return createdTime;
}

public void setCreatedTime(String createdTime) {
this.createdTime = createdTime;
}

public String getDisplayName() {
return displayName;
}

public void setDisplayName(String displayName) {
this.displayName = displayName;
}

public String getLogo() {
return logo;
}

public void setLogo(String logo) {
this.logo = logo;
}

public String getHomepageUrl() {
return homepageUrl;
}

public void setHomepageUrl(String homepageUrl) {
this.homepageUrl = homepageUrl;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

public String getOrganization() {
return organization;
}

public void setOrganization(String organization) {
this.organization = organization;
}

public String getCert() {
return cert;
}

public void setCert(String cert) {
this.cert = cert;
}

public boolean isEnablePassword() {
return enablePassword;
}

public void setEnablePassword(boolean enablePassword) {
this.enablePassword = enablePassword;
}

public boolean isEnableSignUp() {
return enableSignUp;
}

public void setEnableSignUp(boolean enableSignUp) {
this.enableSignUp = enableSignUp;
}

public boolean isEnableSigninSession() {
return enableSigninSession;
}

public void setEnableSigninSession(boolean enableSigninSession) {
this.enableSigninSession = enableSigninSession;
}

public boolean isEnableAutoSignin() {
return enableAutoSignin;
}

public void setEnableAutoSignin(boolean enableAutoSignin) {
this.enableAutoSignin = enableAutoSignin;
}

public boolean isEnableCodeSignin() {
return enableCodeSignin;
}

public void setEnableCodeSignin(boolean enableCodeSignin) {
this.enableCodeSignin = enableCodeSignin;
}

public boolean isEnableSamlCompress() {
return enableSamlCompress;
}

public void setEnableSamlCompress(boolean enableSamlCompress) {
this.enableSamlCompress = enableSamlCompress;
}

public boolean isEnableWebAuthn() {
return enableWebAuthn;
}

public void setEnableWebAuthn(boolean enableWebAuthn) {
this.enableWebAuthn = enableWebAuthn;
}

public boolean isEnableLinkWithEmail() {
return enableLinkWithEmail;
}

public void setEnableLinkWithEmail(boolean enableLinkWithEmail) {
this.enableLinkWithEmail = enableLinkWithEmail;
}

public String getOrgChoiceMode() {
return orgChoiceMode;
}

public void setOrgChoiceMode(String orgChoiceMode) {
this.orgChoiceMode = orgChoiceMode;
}

public String getSamlReplyUrl() {
return samlReplyUrl;
}

public void setSamlReplyUrl(String samlReplyUrl) {
this.samlReplyUrl = samlReplyUrl;
}

public List<String> getGrantTypes() {
return grantTypes;
}

public void setGrantTypes(List<String> grantTypes) {
this.grantTypes = grantTypes;
}

public List<String> getTags() {
return tags;
}

public void setTags(List<String> tags) {
this.tags = tags;
}

public String getClientId() {
return clientId;
}

public void setClientId(String clientId) {
this.clientId = clientId;
}

public String getClientSecret() {
return clientSecret;
}

public void setClientSecret(String clientSecret) {
this.clientSecret = clientSecret;
}

public List<String> getRedirectUris() {
return redirectUris;
}

public void setRedirectUris(List<String> redirectUris) {
this.redirectUris = redirectUris;
}

public String getTokenFormat() {
return tokenFormat;
}

public void setTokenFormat(String tokenFormat) {
this.tokenFormat = tokenFormat;
}

public int getExpireInHours() {
return expireInHours;
}

public void setExpireInHours(int expireInHours) {
this.expireInHours = expireInHours;
}

public int getRefreshExpireInHours() {
return refreshExpireInHours;
}

public void setRefreshExpireInHours(int refreshExpireInHours) {
this.refreshExpireInHours = refreshExpireInHours;
}

public String getSignupUrl() {
return signupUrl;
}

public void setSignupUrl(String signupUrl) {
this.signupUrl = signupUrl;
}

public String getSigninUrl() {
return signinUrl;
}

public void setSigninUrl(String signinUrl) {
this.signinUrl = signinUrl;
}

public String getForgetUrl() {
return forgetUrl;
}

public void setForgetUrl(String forgetUrl) {
this.forgetUrl = forgetUrl;
}

public String getAffiliationUrl() {
return affiliationUrl;
}

public void setAffiliationUrl(String affiliationUrl) {
this.affiliationUrl = affiliationUrl;
}

public String getTermsOfUse() {
return termsOfUse;
}

public void setTermsOfUse(String termsOfUse) {
this.termsOfUse = termsOfUse;
}

public String getSignupHtml() {
return signupHtml;
}

public void setSignupHtml(String signupHtml) {
this.signupHtml = signupHtml;
}

public String getSigninHtml() {
return signinHtml;
}

public void setSigninHtml(String signinHtml) {
this.signinHtml = signinHtml;
}

public String getFormCss() {
return formCss;
}

public void setFormCss(String formCss) {
this.formCss = formCss;
}

public String getFormCssMobile() {
return formCssMobile;
}

public void setFormCssMobile(String formCssMobile) {
this.formCssMobile = formCssMobile;
}

public int getFormOffset() {
return formOffset;
}

public void setFormOffset(int formOffset) {
this.formOffset = formOffset;
}

public String getFormSideHtml() {
return formSideHtml;
}

public void setFormSideHtml(String formSideHtml) {
this.formSideHtml = formSideHtml;
}

public String getFormBackgroundUrl() {
return formBackgroundUrl;
}

public void setFormBackgroundUrl(String formBackgroundUrl) {
this.formBackgroundUrl = formBackgroundUrl;
}


}
18 changes: 11 additions & 7 deletions src/main/java/org/casbin/casdoor/service/ApplicationService.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,23 @@ public ApplicationService(Config config) {

public Application getApplication(String name) throws IOException {
CasdoorResponse<Application, Object> response = doGet("get-application",
Map.of("id", "admin/" + name), new TypeReference<CasdoorResponse<Application, Object>>() {});
Map.of("id", "admin/" + name), new TypeReference<CasdoorResponse<Application, Object>>() {
});
return response.getData();
}

public List<Application> getApplications() throws IOException {
CasdoorResponse<List<Application>, Object> response = doGet("get-applications",
Map.of("owner", "admin"), new TypeReference<CasdoorResponse<List<Application>, Object>>() {});
Map.of("owner", "admin"), new TypeReference<CasdoorResponse<List<Application>, Object>>() {
});
return response.getData();
}

public List<Application> getOrganizationApplications() throws IOException {
CasdoorResponse<List<Application>, Object> response = doGet("get-organization-applications",
Map.of("owner", "admin", "organization", config.getOrganizationName()),
new TypeReference<CasdoorResponse<List<Application>, Object>>() {});
new TypeReference<CasdoorResponse<List<Application>, Object>>() {
});
return response.getData();
}

Expand All @@ -55,8 +58,8 @@ public CasdoorResponse<String, Object> addApplication(Application application) t

public CasdoorResponse<String, Object> deleteApplication(String name) throws IOException {
Application application = new Application();
application.setOwner("admin");
application.setName(name);
application.owner = "admin";
application.name = name;
return modifyApplication(ApplicationOperations.DELETE_APPLICATION, application, null);
}

Expand All @@ -65,9 +68,10 @@ public CasdoorResponse<String, Object> updateApplication(Application application
}

private <T1, T2> CasdoorResponse<T1, T2> modifyApplication(ApplicationOperations method, Application application, java.util.Map<String, String> queryMap) throws IOException {
String id = application.getOwner() + "/" + application.getName();
String id = application.owner + "/" + application.name;
String payload = objectMapper.writeValueAsString(application);
return doPost(method.getOperation(), Map.mergeMap(Map.of("id", id), queryMap), payload,
new TypeReference<CasdoorResponse<T1, T2>>() {});
new TypeReference<CasdoorResponse<T1, T2>>() {
});
}
}
Loading

0 comments on commit c761a42

Please sign in to comment.