Search in sources :

Example 6 with IProject

use of com.openshift.restclient.model.IProject in project jbosstools-openshift by jbosstools.

the class NewApplicationWizardModelTest method setProjectItemsShouldPreserveSelectedProjectIfContained.

@Test
public void setProjectItemsShouldPreserveSelectedProjectIfContained() {
    // pre-conditions
    this.projectItems.add(new ObservableTreeItem(project));
    model.setProject(project);
    IProject selectedProject = model.getProject();
    assertThat(selectedProject).isNotNull();
    // operations
    model.setProjectItems(projectItems);
    // verification
    assertThat(model.getProject()).isEqualTo(selectedProject);
}
Also used : ObservableTreeItem(org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItem) IProject(com.openshift.restclient.model.IProject) Test(org.junit.Test)

Example 7 with IProject

use of com.openshift.restclient.model.IProject in project jbosstools-openshift by jbosstools.

the class NewApplicationWizardModelTest method setProjectToProject2ShouldHaveGetTemplatesReturnTemplatesForProject2.

@Test
public void setProjectToProject2ShouldHaveGetTemplatesReturnTemplatesForProject2() {
    // pre-conditions
    IProject project2 = getProject(1);
    // operations
    model.setProject(project2);
    List<ObservableTreeItem> templates = model.getAppSources();
    // verification
    assertThat(templates).containsAll(getTemplateItemsForProject(1));
}
Also used : ObservableTreeItem(org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItem) IProject(com.openshift.restclient.model.IProject) Test(org.junit.Test)

Example 8 with IProject

use of com.openshift.restclient.model.IProject in project jbosstools-openshift by jbosstools.

the class NewApplicationWizardModelTest method setProjectShouldReturnSameProject.

@Test
public void setProjectShouldReturnSameProject() {
    // pre-conditions
    assertThat(model.getProjectItems().size()).isGreaterThan(2);
    IProject project2 = (IProject) model.getProjectItems().get(1).getModel();
    // operations
    model.setProject(project2);
    // verification
    assertThat(model.getProject()).isEqualTo(project2);
}
Also used : IProject(com.openshift.restclient.model.IProject) Test(org.junit.Test)

Example 9 with IProject

use of com.openshift.restclient.model.IProject in project jbosstools-openshift by jbosstools.

the class DeployImageJob method generateResources.

private Map<String, IResource> generateResources(final Connection connection, final String name) {
    final IResourceFactory factory = connection.getResourceFactory();
    final IProject project = parameters.getProject();
    DockerImageURI sourceImage = getSourceImage();
    Map<String, IResource> resources = new HashMap<>(4);
    IImageStream is = stubImageStream(factory, name, project, sourceImage);
    if (is != null && StringUtils.isBlank(is.getResourceVersion())) {
        resources.put(ResourceKind.IMAGE_STREAM, is);
    }
    resources.put(ResourceKind.SERVICE, stubService(factory, name, SELECTOR_KEY, name));
    if (parameters.isAddRoute()) {
        resources.put(ResourceKind.ROUTE, stubRoute(factory, name, resources.get(ResourceKind.SERVICE).getName()));
    }
    resources.put(ResourceKind.DEPLOYMENT_CONFIG, stubDeploymentConfig(factory, name, sourceImage, is));
    addToGeneratedResources(resources, connection, name, project);
    for (IResource resource : resources.values()) {
        addLabelsToResource(resource);
        resource.setAnnotation(OpenShiftAPIAnnotations.GENERATED_BY, JBOSSTOOLS_OPENSHIFT);
    }
    return resources;
}
Also used : DockerImageURI(com.openshift.restclient.images.DockerImageURI) HashMap(java.util.HashMap) IImageStream(com.openshift.restclient.model.IImageStream) IResourceFactory(com.openshift.restclient.IResourceFactory) IProject(com.openshift.restclient.model.IProject) IResource(com.openshift.restclient.model.IResource)

Example 10 with IProject

use of com.openshift.restclient.model.IProject in project jbosstools-openshift by jbosstools.

the class ConnectionWrapper method startLoadJob.

void startLoadJob(ProjectWrapper projectWrapper, IExceptionHandler handler) {
    new Job(NLS.bind("Loading OpenShift project {0}...", projectWrapper.getWrapped().getName())) {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            try {
                IProject project = projectWrapper.getWrapped();
                IOpenShiftConnection connection = projectWrapper.getParent().getWrapped();
                WatchManager.getInstance().startWatch(project, connection);
                Collection<IResource> resources = new HashSet<>();
                for (String kind : RESOURCE_KINDS) {
                    resources.addAll(getWrapped().getResources(kind, project.getNamespaceName()));
                }
                resources.forEach(r -> resourceCache.add(r));
                projectWrapper.initWithResources(resources);
                projectWrapper.fireChanged();
            } catch (OperationCanceledException e) {
                projectWrapper.setLoadingState(LoadingState.LOAD_STOPPED);
            } catch (Throwable e) {
                projectWrapper.setLoadingState(LoadingState.LOAD_STOPPED);
                handler.handleException(e);
            }
            return Status.OK_STATUS;
        }
    }.schedule();
}
Also used : IResource(com.openshift.restclient.model.IResource) ResourceKind(com.openshift.restclient.ResourceKind) Job(org.eclipse.core.runtime.jobs.Job) NLS(org.eclipse.osgi.util.NLS) Collection(java.util.Collection) ConnectionProperties(org.jboss.tools.openshift.core.connection.ConnectionProperties) ResourceUtils(org.jboss.tools.openshift.internal.core.util.ResourceUtils) Status(org.eclipse.core.runtime.Status) HashMap(java.util.HashMap) AtomicReference(java.util.concurrent.atomic.AtomicReference) IProject(com.openshift.restclient.model.IProject) ArrayList(java.util.ArrayList) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IOpenShiftConnection(org.jboss.tools.openshift.core.connection.IOpenShiftConnection) HashSet(java.util.HashSet) List(java.util.List) IStatus(org.eclipse.core.runtime.IStatus) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) WatchManager(org.jboss.tools.openshift.internal.core.WatchManager) Map(java.util.Map) Collections(java.util.Collections) OpenShiftUIActivator(org.jboss.tools.openshift.internal.ui.OpenShiftUIActivator) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) IOpenShiftConnection(org.jboss.tools.openshift.core.connection.IOpenShiftConnection) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) Collection(java.util.Collection) Job(org.eclipse.core.runtime.jobs.Job) IProject(com.openshift.restclient.model.IProject)

Aggregations

IProject (com.openshift.restclient.model.IProject)49 Test (org.junit.Test)18 Connection (org.jboss.tools.openshift.core.connection.Connection)16 IResource (com.openshift.restclient.model.IResource)13 ArrayList (java.util.ArrayList)8 IConnection (org.jboss.tools.openshift.common.core.connection.IConnection)7 ResourceKind (com.openshift.restclient.ResourceKind)6 IStatus (org.eclipse.core.runtime.IStatus)6 ObservableTreeItem (org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItem)6 List (java.util.List)5 ISelection (org.eclipse.jface.viewers.ISelection)5 IService (com.openshift.restclient.model.IService)4 IRoute (com.openshift.restclient.model.route.IRoute)4 Collection (java.util.Collection)4 Collections (java.util.Collections)4 HashMap (java.util.HashMap)4 OpenShiftException (com.openshift.restclient.OpenShiftException)3 IBuildConfig (com.openshift.restclient.model.IBuildConfig)3 Map (java.util.Map)3 Collectors (java.util.stream.Collectors)3