Skip to content

Commit

Permalink
[JBIDE-12142] fixed IUser#refresh: added missing api#refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
adietish committed Aug 6, 2012
1 parent 222bdc6 commit a2a7036
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 10 deletions.
17 changes: 12 additions & 5 deletions src/main/java/com/openshift/internal/client/APIResource.java
Expand Up @@ -11,6 +11,7 @@
package com.openshift.internal.client;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -41,6 +42,7 @@ public class APIResource extends AbstractOpenShiftResource implements IOpenShift
private final String password;
private List<IDomain> domains;
private UserResource user;
//TODO: implement switch that allows to turn ssl checks on/off
private boolean doSSLChecks = false;
private final List<ICartridge> standaloneCartridgeNames = new ArrayList<ICartridge>();
private final List<IEmbeddableCartridge> embeddedCartridgeNames = new ArrayList<IEmbeddableCartridge>();
Expand All @@ -59,9 +61,6 @@ protected final String getLogin() {
return login;
}

/**
* @return the password
*/
protected final String getPassword() {
return password;
}
Expand Down Expand Up @@ -94,7 +93,7 @@ public IUser getUser() throws OpenShiftException {
}

public List<IDomain> getDomains() throws OpenShiftException {
if (this.domains == null) {
if (domains == null) {
this.domains = loadDomains();
}
return CollectionUtils.toUnmodifiableCopy(this.domains);
Expand All @@ -117,6 +116,14 @@ public IDomain getDomain(String id) throws OpenShiftException {
return null;
}

public IDomain getDefaultDomain() {
final List<IDomain> domains = getDomains();
if (domains.size() > 0) {
return domains.get(0);
}
return null;
}

public IDomain createDomain(String id) throws OpenShiftException {
if (hasDomain(id)) {
throw new OpenShiftException("Domain {0} already exists", id);
Expand Down Expand Up @@ -160,6 +167,7 @@ private void retrieveCartridges() throws OpenShiftException {

@Override
public void refresh() throws OpenShiftException {
this.domains = null;
}

/**
Expand Down Expand Up @@ -219,5 +227,4 @@ public List<CartridgeResourceDTO> execute() throws OpenShiftException {
return super.execute();
}
}

}
8 changes: 3 additions & 5 deletions src/main/java/com/openshift/internal/client/UserResource.java
Expand Up @@ -89,11 +89,7 @@ public List<IDomain> getDomains() throws OpenShiftException {
}

public IDomain getDefaultDomain() throws OpenShiftException {
final List<IDomain> domains = api.getDomains();
if (domains.size() > 0) {
return domains.get(0);
}
return null;
return api.getDefaultDomain();
}

public IDomain getDomain(String namespace) throws OpenShiftException {
Expand All @@ -109,6 +105,8 @@ public void refresh() throws OpenShiftException {
this.sshKeys = null;
loadKeys();
}

api.refresh();
DomainResource defaultDomain = (DomainResource) getDefaultDomain();
if (defaultDomain != null) {
defaultDomain.refresh();
Expand Down
Expand Up @@ -13,8 +13,10 @@
import static org.fest.assertions.Assertions.assertThat;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.List;

Expand Down Expand Up @@ -102,4 +104,23 @@ public void shouldReturnDomains() throws OpenShiftException {
// verification
assertThat(domains).isNotEmpty();
}

@Test
public void shouldNoDefaultDomainAfterRefresh() throws OpenShiftException, FileNotFoundException, IOException {
// precondition
IDomain domain = DomainTestUtils.getFirstDomainOrCreate(user);
assertNotNull(user.getDefaultDomain());
assertNotNull(domain);

IUser otherUser = new TestConnectionFactory().getConnection().getUser();
DomainTestUtils.silentlyDestroyAllDomains(otherUser);
assertNull(otherUser.getDefaultDomain());

// operation
user.refresh();

// verification
assertNull(user.getDefaultDomain());
}

}

0 comments on commit a2a7036

Please sign in to comment.