-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
38 changed files
with
1,118 additions
and
119 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
cascades-server/app/src/test/java/pl/gov/coi/cascades/server/AppMainStartTestIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package pl.gov.coi.cascades.server; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.Mock; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.context.ConfigurableApplicationContext; | ||
import org.springframework.test.context.junit4.SpringRunner; | ||
|
||
import static org.mockito.Matchers.any; | ||
import static org.mockito.Matchers.anyVararg; | ||
import static org.mockito.Mockito.when; | ||
|
||
/** | ||
* @author <a href="mailto:lukasz.malek@coi.gov.pl">Łukasz Małek</a> | ||
*/ | ||
@RunWith(SpringRunner.class) | ||
@SpringBootTest(classes = AppMain.class) | ||
@ProductionHibernateTest | ||
public class AppMainStartTestIT { | ||
|
||
@Mock | ||
private SpringApplicationFactory applicationFactory; | ||
|
||
@Mock | ||
private SpringApplication application; | ||
|
||
@Mock | ||
private ConfigurableApplicationContext applicationContext; | ||
|
||
@Test | ||
public void shouldApplicationStartOnProductionProfile(){ | ||
//given | ||
AppMain.setAppMainSupplier(() -> new AppMain(applicationFactory)); | ||
|
||
when(applicationFactory.create(any())).thenReturn(application); | ||
when(application.run(anyVararg())).thenReturn(applicationContext); | ||
when(applicationContext.isActive()).thenReturn(true); | ||
|
||
// when | ||
try { | ||
AppMain.main(new String[0]); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
cascades-server/app/src/test/java/pl/gov/coi/cascades/server/ProdactionHibernateTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package pl.gov.coi.cascades.server; | ||
|
||
import org.springframework.test.context.ActiveProfiles; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* @author <a href="mailto:lukasz.malek@coi.gov.pl">Łukasz Małek</a> | ||
*/ | ||
@Target(ElementType.TYPE) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@ActiveProfiles({Environment.PRODUCTION_NAME, ProfileType.HIBERNATE_NAME}) | ||
@interface ProductionHibernateTest { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
...server/configuration/src/main/java/pl/gov/coi/cascades/server/DatabaseOperationsImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package pl.gov.coi.cascades.server; | ||
|
||
import lombok.AllArgsConstructor; | ||
import pl.gov.coi.cascades.contract.domain.NetworkBind; | ||
import pl.gov.coi.cascades.contract.domain.Template; | ||
import pl.gov.coi.cascades.server.domain.DatabaseInstance; | ||
import pl.gov.coi.cascades.server.domain.DatabaseOperations; | ||
import pl.gov.coi.cascades.server.domain.TemplateIdGateway; | ||
import pl.wavesoftware.eid.exceptions.EidIllegalArgumentException; | ||
|
||
import java.util.Optional; | ||
|
||
@AllArgsConstructor | ||
public class DatabaseOperationsImpl implements DatabaseOperations { | ||
|
||
private ServerConfigurationService serverConfigurationService; | ||
private TemplateIdGateway templateIdGateway; | ||
|
||
@Override | ||
@Deprecated | ||
public NetworkBind createDatabase(DatabaseInstance databaseInstance) { | ||
String templateId = databaseInstance.getTemplate().getId(); | ||
NetworkBind networkBind = getNetworkBind(templateId); | ||
// TODO: write implementation | ||
|
||
return networkBind; | ||
} | ||
|
||
@Override | ||
@Deprecated | ||
public void deleteDatabase(DatabaseInstance databaseInstance) { | ||
// TODO: write implementation | ||
throw new UnsupportedOperationException("Not yet implemented!"); | ||
} | ||
|
||
private NetworkBind getNetworkBind(String templateId) { | ||
Optional<Template> templateOptional = templateIdGateway.find(templateId); | ||
Template template = templateOptional != null ? templateOptional.orElse(null) : null; | ||
|
||
if (template != null) { | ||
Optional<ServerDef> correctServerDef = serverConfigurationService | ||
.getManagedServers() | ||
.stream() | ||
.filter(p -> p.getServerId() | ||
.equalsIgnoreCase(template.getServerId()) | ||
) | ||
.findFirst(); | ||
|
||
ServerDef serverDef = correctServerDef.orElse(null); | ||
|
||
if (serverDef != null) { | ||
return new NetworkBindImpl(serverDef.getHost(), serverDef.getPort()); | ||
} | ||
} | ||
|
||
throw new EidIllegalArgumentException( | ||
"20180628:191916", | ||
"Given templateId with serverID hasn't been found in connection settings." | ||
); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
cascades-server/configuration/src/main/java/pl/gov/coi/cascades/server/NetworkBindImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package pl.gov.coi.cascades.server; | ||
|
||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
import pl.gov.coi.cascades.contract.domain.NetworkBind; | ||
|
||
@AllArgsConstructor | ||
@Getter | ||
@Setter | ||
public class NetworkBindImpl implements NetworkBind { | ||
|
||
private String host; | ||
private int port; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.