Skip to content

Commit

Permalink
return devfile v2 as a default devfile
Browse files Browse the repository at this point in the history
  • Loading branch information
vinokurig committed Jul 16, 2024
1 parent 5459a69 commit e5578f7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import org.eclipse.che.api.factory.server.scm.AuthorisationRequestManager;
import org.eclipse.che.api.factory.server.urlfactory.RemoteFactoryUrl;
import org.eclipse.che.api.factory.server.urlfactory.URLFactoryBuilder;
import org.eclipse.che.api.factory.shared.dto.FactoryDto;
import org.eclipse.che.api.factory.shared.dto.FactoryDevfileV2Dto;
import org.eclipse.che.api.factory.shared.dto.FactoryMetaDto;
import org.eclipse.che.api.factory.shared.dto.FactoryVisitor;
import org.eclipse.che.api.workspace.server.devfile.FileContentProvider;
Expand Down Expand Up @@ -60,7 +60,12 @@ protected FactoryMetaDto createFactory(
contentProvider,
extractOverrideParams(factoryParameters),
getSkipAuthorisation(factoryParameters))
.orElseGet(() -> newDto(FactoryDto.class).withV(CURRENT_VERSION).withSource("repo"))
.orElseGet(
() ->
newDto(FactoryDevfileV2Dto.class)
.withDevfile(Map.of("schemaVersion", "2.3.0"))
.withV(CURRENT_VERSION)
.withSource("repo"))
.acceptVisitor(factoryVisitor);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,20 @@
package org.eclipse.che.api.factory.server;

import static java.util.Collections.emptyMap;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;

import java.util.Map;
import org.eclipse.che.api.factory.server.scm.AuthorisationRequestManager;
import org.eclipse.che.api.factory.server.urlfactory.RemoteFactoryUrl;
import org.eclipse.che.api.factory.server.urlfactory.URLFactoryBuilder;
import org.eclipse.che.api.factory.shared.dto.FactoryDevfileV2Dto;
import org.eclipse.che.api.factory.shared.dto.FactoryVisitor;
import org.eclipse.che.api.workspace.server.devfile.FileContentProvider;
import org.mockito.Mock;
import org.mockito.testng.MockitoTestNGListener;
import org.testng.annotations.BeforeMethod;
Expand All @@ -31,7 +37,9 @@ public class BaseFactoryParameterResolverTest {

@Mock private AuthorisationRequestManager authorisationRequestManager;
@Mock private URLFactoryBuilder urlFactoryBuilder;

@Mock private RemoteFactoryUrl remoteFactoryUrl;
@Mock private FactoryVisitor factoryVisitor;
@Mock private FileContentProvider contentProvider;
private static final String PROVIDER_NAME = "test";

private BaseFactoryParameterResolver baseFactoryParameterResolver;
Expand Down Expand Up @@ -73,4 +81,15 @@ public void shouldReturnTrueOnGetSkipAuthorisationFromFactoryParams() {
// then
assertTrue(result);
}

@Test
public void shouldReturnDevfileV2() throws Exception {
// given
when(authorisationRequestManager.isStored(eq(PROVIDER_NAME))).thenReturn(false);
// when
baseFactoryParameterResolver.createFactory(
emptyMap(), remoteFactoryUrl, factoryVisitor, contentProvider);
// then
verify(factoryVisitor).visit(any(FactoryDevfileV2Dto.class));
}
}

0 comments on commit e5578f7

Please sign in to comment.