From 04dad8d6de3713b1ca7a0b4e0ccf24a87afb0bd2 Mon Sep 17 00:00:00 2001 From: kaizimmerm Date: Thu, 7 Jul 2016 12:39:40 +0200 Subject: [PATCH 01/24] Started migration for Boot 1.3 and Security 4.1 Signed-off-by: kaizimmerm --- .../{logback.xml => logback-spring.xml} | 2 +- .../{logback.xml => logback-spring.xml} | 6 +- .../ArtifactStoreAutoConfiguration.java | 2 - .../repository/MongoConfiguration.java | 119 ------------------ .../hawkbit/artifact/FreePortFileWriter.java | 75 ----------- .../hawkbit/artifact/MongoDBTestRule.java | 115 ----------------- .../repository/ArtifactStoreTest.java | 7 +- .../SecurityManagedConfiguration.java | 61 +-------- .../resource/DdiArtifactDownloadTest.java | 25 ++-- .../{logback.xml => logback-spring.xml} | 4 +- .../{logback.xml => logback-spring.xml} | 2 +- ...actHttpControllerAuthenticationFilter.java | 2 +- ...MRessourceMisingMongoDbConnectionTest.java | 23 ++-- .../{logback.xml => logback-spring.xml} | 2 +- .../ArtifactManagementFailedMongoDBTest.java | 74 +++++++++++ .../jpa/ArtifactManagementNoMongoDbTest.java | 58 --------- .../jpa/ArtifactManagementTest.java | 32 ----- .../src/test/resources/logback-spring.xml | 19 +++ .../test/util/AbstractIntegrationTest.java | 2 + .../AbstractIntegrationTestWithMongoDB.java | 82 +----------- .../test/util/FreePortFileWriter.java | 75 ----------- .../test/util/TestConfiguration.java | 3 +- .../im/authentication/SpPermission.java | 3 +- .../security/HawkbitSecurityProperties.java | 40 ------ pom.xml | 16 +-- 25 files changed, 146 insertions(+), 703 deletions(-) rename examples/hawkbit-example-app/src/main/resources/{logback.xml => logback-spring.xml} (96%) rename examples/hawkbit-example-mgmt-simulator/src/main/resources/{logback.xml => logback-spring.xml} (88%) delete mode 100644 hawkbit-artifact-repository-mongo/src/main/java/org/eclipse/hawkbit/artifact/repository/MongoConfiguration.java delete mode 100644 hawkbit-artifact-repository-mongo/src/test/java/org/eclipse/hawkbit/artifact/FreePortFileWriter.java delete mode 100644 hawkbit-artifact-repository-mongo/src/test/java/org/eclipse/hawkbit/artifact/MongoDBTestRule.java rename hawkbit-ddi-resource/src/test/resources/{logback.xml => logback-spring.xml} (79%) rename hawkbit-dmf-amqp/src/test/resources/{logback.xml => logback-spring.xml} (97%) rename hawkbit-mgmt-resource/src/test/resources/{logback.xml => logback-spring.xml} (97%) create mode 100644 hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ArtifactManagementFailedMongoDBTest.java delete mode 100644 hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ArtifactManagementNoMongoDbTest.java create mode 100644 hawkbit-repository/hawkbit-repository-jpa/src/test/resources/logback-spring.xml delete mode 100644 hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/FreePortFileWriter.java diff --git a/examples/hawkbit-example-app/src/main/resources/logback.xml b/examples/hawkbit-example-app/src/main/resources/logback-spring.xml similarity index 96% rename from examples/hawkbit-example-app/src/main/resources/logback.xml rename to examples/hawkbit-example-app/src/main/resources/logback-spring.xml index a76e39683..2f64ef001 100644 --- a/examples/hawkbit-example-app/src/main/resources/logback.xml +++ b/examples/hawkbit-example-app/src/main/resources/logback-spring.xml @@ -26,7 +26,7 @@ - + \ No newline at end of file diff --git a/examples/hawkbit-example-mgmt-simulator/src/main/resources/logback.xml b/examples/hawkbit-example-mgmt-simulator/src/main/resources/logback-spring.xml similarity index 88% rename from examples/hawkbit-example-mgmt-simulator/src/main/resources/logback.xml rename to examples/hawkbit-example-mgmt-simulator/src/main/resources/logback-spring.xml index 768f30687..765fdb869 100644 --- a/examples/hawkbit-example-mgmt-simulator/src/main/resources/logback.xml +++ b/examples/hawkbit-example-mgmt-simulator/src/main/resources/logback-spring.xml @@ -14,8 +14,8 @@ - - - + + + \ No newline at end of file diff --git a/hawkbit-artifact-repository-mongo/src/main/java/org/eclipse/hawkbit/artifact/repository/ArtifactStoreAutoConfiguration.java b/hawkbit-artifact-repository-mongo/src/main/java/org/eclipse/hawkbit/artifact/repository/ArtifactStoreAutoConfiguration.java index 8a1cb89a9..38df78dcb 100644 --- a/hawkbit-artifact-repository-mongo/src/main/java/org/eclipse/hawkbit/artifact/repository/ArtifactStoreAutoConfiguration.java +++ b/hawkbit-artifact-repository-mongo/src/main/java/org/eclipse/hawkbit/artifact/repository/ArtifactStoreAutoConfiguration.java @@ -11,14 +11,12 @@ package org.eclipse.hawkbit.artifact.repository; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Import; /** * Auto configuration for the {@link ArtifactStore}. */ @Configuration @ConditionalOnMissingBean(value = ArtifactRepository.class) -@Import(value = MongoConfiguration.class) public class ArtifactStoreAutoConfiguration { /** diff --git a/hawkbit-artifact-repository-mongo/src/main/java/org/eclipse/hawkbit/artifact/repository/MongoConfiguration.java b/hawkbit-artifact-repository-mongo/src/main/java/org/eclipse/hawkbit/artifact/repository/MongoConfiguration.java deleted file mode 100644 index e01c6a455..000000000 --- a/hawkbit-artifact-repository-mongo/src/main/java/org/eclipse/hawkbit/artifact/repository/MongoConfiguration.java +++ /dev/null @@ -1,119 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.artifact.repository; - -import java.net.UnknownHostException; -import java.util.Arrays; - -import javax.annotation.PreDestroy; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.boot.autoconfigure.mongo.MongoProperties; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Profile; -import org.springframework.data.mongodb.config.AbstractMongoConfiguration; - -import com.mongodb.Mongo; -import com.mongodb.MongoClient; -import com.mongodb.MongoClientOptions; -import com.mongodb.MongoClientOptions.Builder; -import com.mongodb.MongoClientURI; -import com.mongodb.ServerAddress; - -/** - * {@link AbstractMongoConfiguration} that uses {@link MongoClientURI} even when - * port is configured for NON {@link Cloud} use cases. - * - */ -@Configuration -@EnableConfigurationProperties(MongoProperties.class) -@ConditionalOnClass(Mongo.class) -@ConditionalOnMissingBean(type = "org.springframework.data.mongodb.MongoDbFactory") -@Profile({ "!cloud" }) -public class MongoConfiguration extends AbstractMongoConfiguration { - private static final Logger LOG = LoggerFactory.getLogger(MongoConfiguration.class); - - @Autowired - private MongoProperties properties; - - @Autowired(required = false) - private MongoClientOptions options; - - private Mongo mongoConnection; - - @Override - public String getDatabaseName() { - return properties.getMongoClientDatabase(); - } - - /** - * Closes mongo client when destroyed. - */ - @PreDestroy - public void close() { - if (this.mongoConnection != null) { - this.mongoConnection.close(); - } - } - - @Override - @Bean - @ConditionalOnMissingBean - // Closed by pre-destroy - @SuppressWarnings({ "squid:S2095" }) - public Mongo mongo() throws UnknownHostException { - final MongoClientURI uri = new MongoClientURI(properties.getUri(), createBuilderOutOfOptions(options)); - - if (properties.getPort() != null) { - LOG.debug("Create mongo by properties (host: {}, port: {})", uri.getHosts().get(0), properties.getPort()); - this.mongoConnection = new MongoClient( - Arrays.asList(new ServerAddress(uri.getHosts().get(0), properties.getPort())), uri.getOptions()); - } else { - LOG.debug("Create mongo by URI : {}", uri); - this.mongoConnection = new MongoClient(uri); - } - - return this.mongoConnection; - } - - /* - * Creates {@link MongoClientOptions} builder out of existing options as the - * {@link MongoClientURI} expects a builder. - * - * Based on MongoProperties#builder method. - */ - private static Builder createBuilderOutOfOptions(final MongoClientOptions options) { - final Builder builder = MongoClientOptions.builder(); - if (options != null) { - builder.alwaysUseMBeans(options.isAlwaysUseMBeans()); - builder.connectionsPerHost(options.getConnectionsPerHost()); - builder.connectTimeout(options.getConnectTimeout()); - builder.cursorFinalizerEnabled(options.isCursorFinalizerEnabled()); - builder.dbDecoderFactory(options.getDbDecoderFactory()); - builder.dbEncoderFactory(options.getDbEncoderFactory()); - builder.description(options.getDescription()); - builder.maxWaitTime(options.getMaxWaitTime()); - builder.readPreference(options.getReadPreference()); - builder.serverSelectionTimeout(options.getServerSelectionTimeout()); - builder.socketFactory(options.getSocketFactory()); - builder.socketKeepAlive(options.isSocketKeepAlive()); - builder.socketTimeout(options.getSocketTimeout()); - builder.threadsAllowedToBlockForConnectionMultiplier( - options.getThreadsAllowedToBlockForConnectionMultiplier()); - builder.writeConcern(options.getWriteConcern()); - } - return builder; - } -} diff --git a/hawkbit-artifact-repository-mongo/src/test/java/org/eclipse/hawkbit/artifact/FreePortFileWriter.java b/hawkbit-artifact-repository-mongo/src/test/java/org/eclipse/hawkbit/artifact/FreePortFileWriter.java deleted file mode 100644 index 257c85076..000000000 --- a/hawkbit-artifact-repository-mongo/src/test/java/org/eclipse/hawkbit/artifact/FreePortFileWriter.java +++ /dev/null @@ -1,75 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.artifact; - -import java.io.File; -import java.net.InetSocketAddress; -import java.net.ServerSocket; - -/** - * - * - */ -public class FreePortFileWriter { - - private final String filePortPath; - private final int from; - private final int to; - - /** - * @param from - * @param to - */ - public FreePortFileWriter(final int from, final int to, final String filePortPath) { - this.from = from; - this.to = to; - this.filePortPath = filePortPath; - } - - public int getPort() { - return findFree(); - } - - protected int findFree() { - for (int i = from; i <= to; i++) { - if (isFree(i)) { - return i; - } - } - throw new RuntimeException("No free port in range " + from + ":" + to); - } - - boolean isFree(final int port) { - try { - final File portFile = new File(filePortPath + File.separator + port + ".port"); - portFile.getParentFile().mkdirs(); - if (portFile.exists()) { - return false; - } else { - boolean isFree = false; - final ServerSocket sock = new ServerSocket(); - sock.setReuseAddress(true); - sock.bind(new InetSocketAddress(port)); - if (portFile.createNewFile()) { - portFile.deleteOnExit(); - isFree = true; - } - sock.close(); - // is free: - return isFree; - // We rely on an exception thrown to determine availability or - // not availability. - } - } catch (final Exception e) { - // not free. - return false; - } - } - -} diff --git a/hawkbit-artifact-repository-mongo/src/test/java/org/eclipse/hawkbit/artifact/MongoDBTestRule.java b/hawkbit-artifact-repository-mongo/src/test/java/org/eclipse/hawkbit/artifact/MongoDBTestRule.java deleted file mode 100644 index f5d88ceaa..000000000 --- a/hawkbit-artifact-repository-mongo/src/test/java/org/eclipse/hawkbit/artifact/MongoDBTestRule.java +++ /dev/null @@ -1,115 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.artifact; - -import java.io.IOException; -import java.net.UnknownHostException; -import java.util.UUID; - -import org.junit.rules.TestRule; -import org.junit.runner.Description; -import org.junit.runners.model.Statement; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import de.flapdoodle.embed.mongo.Command; -import de.flapdoodle.embed.mongo.MongodExecutable; -import de.flapdoodle.embed.mongo.MongodProcess; -import de.flapdoodle.embed.mongo.MongodStarter; -import de.flapdoodle.embed.mongo.config.ArtifactStoreBuilder; -import de.flapdoodle.embed.mongo.config.DownloadConfigBuilder; -import de.flapdoodle.embed.mongo.config.IMongodConfig; -import de.flapdoodle.embed.mongo.config.MongodConfigBuilder; -import de.flapdoodle.embed.mongo.config.Net; -import de.flapdoodle.embed.mongo.config.RuntimeConfigBuilder; -import de.flapdoodle.embed.mongo.distribution.Version; -import de.flapdoodle.embed.process.config.store.HttpProxyFactory; -import de.flapdoodle.embed.process.runtime.Network; - -/** - * - * - */ -public class MongoDBTestRule implements TestRule { - - private static final Logger LOG = LoggerFactory.getLogger(MongoDBTestRule.class); - private static volatile MongodExecutable mongodExecutable = null; - private static volatile MongodProcess mongod; - private final String id = UUID.randomUUID().toString(); - - @Override - public Statement apply(final Statement base, final Description description) { - return statement(base, description); - } - - private Statement statement(final Statement base, final Description description) { - return new Statement() { - @Override - public void evaluate() throws Throwable { - before(base, description); - try { - base.evaluate(); - } finally { - after(); - } - } - }; - } - - private void after() { - if (mongodExecutable != null) { - LOG.info("Stop MongoDB..."); - mongodExecutable.stop(); - mongodExecutable = null; - if (mongod != null) { - mongod.stop(); - mongod = null; - } - LOG.info("MongoDB stopped... {}", id); - } - } - - private void before(final Statement base, final Description description) throws UnknownHostException, IOException { - final Command command = Command.MongoD; - - final RuntimeConfigBuilder runtimeConfig = new RuntimeConfigBuilder().defaults(command); - - int port = -1; - if (System.getProperty("spring.data.mongodb.port") != null) { - port = Integer.parseInt(System.getProperty("spring.data.mongodb.port")); - } else { - port = new FreePortFileWriter(27017, 27100, "./target/freeports").getPort(); - System.setProperty("spring.data.mongodb.port", String.valueOf(port)); - } - - Version version = Version.V3_0_8; - if (System.getProperty("inf.mongodb.version") != null) { - version = Version.valueOf("V" + System.getProperty("inf.mongodb.version").trim().replaceAll("\\.", "_")); - } - - if (System.getProperty("http.proxyHost") != null) { - runtimeConfig.artifactStore(new ArtifactStoreBuilder().defaults(command) - .download(new DownloadConfigBuilder().defaultsForCommand(command) - .proxyFactory(new HttpProxyFactory(System.getProperty("http.proxyHost").trim(), - Integer.valueOf(System.getProperty("http.proxyPort")))))); - } - - final IMongodConfig mongodConfig = new MongodConfigBuilder().version(version) - .net(new Net("127.0.0.1", port, Network.localhostIsIPv6())).build(); - - final MongodStarter starter = MongodStarter.getInstance(runtimeConfig.build()); - mongodExecutable = starter.prepare(mongodConfig); - LOG.info("Start MongoDB..."); - mongod = mongodExecutable.start(); - - final Net net = mongod.getConfig().net(); - LOG.info("MongoDB started id {} on bind ip :{} Port:{} and version {}", id, net.getBindIp(), net.getPort(), - mongodConfig.version().toString()); - } -} diff --git a/hawkbit-artifact-repository-mongo/src/test/java/org/eclipse/hawkbit/artifact/repository/ArtifactStoreTest.java b/hawkbit-artifact-repository-mongo/src/test/java/org/eclipse/hawkbit/artifact/repository/ArtifactStoreTest.java index c5aca8e1a..fb7c141e1 100644 --- a/hawkbit-artifact-repository-mongo/src/test/java/org/eclipse/hawkbit/artifact/repository/ArtifactStoreTest.java +++ b/hawkbit-artifact-repository-mongo/src/test/java/org/eclipse/hawkbit/artifact/repository/ArtifactStoreTest.java @@ -18,10 +18,8 @@ import java.security.NoSuchAlgorithmException; import java.util.Random; import org.apache.commons.io.IOUtils; -import org.eclipse.hawkbit.artifact.MongoDBTestRule; import org.eclipse.hawkbit.artifact.TestConfiguration; import org.eclipse.hawkbit.artifact.repository.model.DbArtifact; -import org.junit.ClassRule; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -29,6 +27,7 @@ import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.data.mongodb.core.query.Criteria; import org.springframework.data.mongodb.core.query.Query; import org.springframework.data.mongodb.gridfs.GridFsOperations; +import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import com.google.common.io.BaseEncoding; @@ -42,11 +41,9 @@ import ru.yandex.qatools.allure.annotations.Stories; @Stories("Artifact Store MongoDB") @RunWith(SpringJUnit4ClassRunner.class) @SpringApplicationConfiguration(classes = { ArtifactStoreAutoConfiguration.class, TestConfiguration.class }) +@TestPropertySource(properties = { "spring.data.mongodb.port=0", "spring.mongodb.embedded.version=3.2.7" }) public class ArtifactStoreTest { - @ClassRule - public static final MongoDBTestRule mongoDBRule = new MongoDBTestRule(); - @Autowired private ArtifactStore artifactStoreUnderTest; diff --git a/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/security/SecurityManagedConfiguration.java b/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/security/SecurityManagedConfiguration.java index 1e4dbfb27..a0d329ffa 100644 --- a/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/security/SecurityManagedConfiguration.java +++ b/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/security/SecurityManagedConfiguration.java @@ -13,7 +13,6 @@ import static org.springframework.context.annotation.AdviceMode.ASPECTJ; import static org.springframework.core.Ordered.HIGHEST_PRECEDENCE; import java.io.IOException; -import java.net.URI; import javax.annotation.PostConstruct; import javax.servlet.Filter; @@ -22,7 +21,6 @@ import javax.servlet.FilterConfig; import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; -import javax.validation.constraints.NotNull; import org.eclipse.hawkbit.ExcludePathAwareShallowETagFilter; import org.eclipse.hawkbit.cache.CacheConstants; @@ -69,7 +67,6 @@ import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.builders.WebSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; -import org.springframework.security.config.annotation.web.servlet.configuration.EnableWebMvcSecurity; import org.springframework.security.config.http.SessionCreationPolicy; import org.springframework.security.core.Authentication; import org.springframework.security.core.authority.SimpleGrantedAuthority; @@ -79,9 +76,6 @@ import org.springframework.security.web.authentication.LoginUrlAuthenticationEnt import org.springframework.security.web.authentication.preauth.RequestHeaderAuthenticationFilter; import org.springframework.security.web.authentication.www.BasicAuthenticationEntryPoint; import org.springframework.security.web.authentication.www.BasicAuthenticationFilter; -import org.springframework.security.web.header.writers.frameoptions.StaticAllowFromStrategy; -import org.springframework.security.web.header.writers.frameoptions.XFrameOptionsHeaderWriter; -import org.springframework.security.web.header.writers.frameoptions.XFrameOptionsHeaderWriter.XFrameOptionsMode; import org.springframework.security.web.session.HttpSessionEventPublisher; import org.springframework.security.web.session.SessionManagementFilter; import org.vaadin.spring.security.VaadinSecurityContext; @@ -98,7 +92,6 @@ import org.vaadin.spring.security.web.authentication.VaadinUrlAuthenticationSucc @Configuration @EnableWebSecurity @EnableGlobalMethodSecurity(prePostEnabled = true, mode = ASPECTJ, proxyTargetClass = true, securedEnabled = true) -@EnableWebMvcSecurity @Order(value = HIGHEST_PRECEDENCE) public class SecurityManagedConfiguration { @@ -188,9 +181,7 @@ public class SecurityManagedConfiguration { controllerAnonymousDownloadFilter.setCheckForPrincipalChanges(true); controllerAnonymousDownloadFilter.setAuthenticationDetailsSource(authenticationDetailsSource); - HttpSecurity httpSec = http.csrf().disable().headers() - .addHeaderWriter(new XFrameOptionsHeaderWriter(XFrameOptionsMode.DENY)).contentTypeOptions() - .xssProtection().httpStrictTransportSecurity().and(); + HttpSecurity httpSec = http.csrf().disable(); if (springSecurityProperties.isRequireSsl()) { httpSec = httpSec.requiresChannel().anyRequest().requiresSecure().and(); @@ -336,20 +327,12 @@ public class SecurityManagedConfiguration { @Order(400) @EnableVaadinSecurity public static class UISecurityConfigurationAdapter extends WebSecurityConfigurerAdapter { - - private static final String XFRAME_OPTION_DENY = "DENY"; - private static final String XFRAME_OPTION_SAMEORIGIN = "SAMEORIGIN"; - private static final String XFAME_OPTION_ALLOW_FROM = "ALLOW-FROM"; - @Autowired private VaadinSecurityContext vaadinSecurityContext; @Autowired private org.springframework.boot.autoconfigure.security.SecurityProperties springSecurityProperties; - @Autowired - private HawkbitSecurityProperties securityProperties; - /** * post construct for setting the authentication success handler for the * vaadin security context. @@ -403,18 +386,6 @@ public class SecurityManagedConfiguration { @Override protected void configure(final HttpSecurity http) throws Exception { - // configuration xframe-option - final String confXframeOption = securityProperties.getXframe().getOption(); - final String confAllowFromUri = securityProperties.getXframe().getAllowfrom(); - - if (XFAME_OPTION_ALLOW_FROM.equals(confXframeOption) && confAllowFromUri.isEmpty()) { - // if allow-from option is specified but no allowFromUri throw - // exception - throw new IllegalStateException("hawkbit.server.security.xframe.option has been specified as ALLOW-FROM" - + " but no hawkbit.server.security.xframe.allowfrom has been set, " - + "please ensure to set allow from URIs"); - } - // workaround regex: we need to exclude the URL /UI/HEARTBEAT here // because we bound the vaadin application to /UI and not to root, // described in vaadin-forum: @@ -431,12 +402,7 @@ public class SecurityManagedConfiguration { "\"******************\\n** Requires HTTPS Security has been disabled for UI, should only be used for developing purposes **\\n******************\""); } - // for UI integrator we allow frame integration on same origin - httpSec.headers() - .addHeaderWriter(confXframeOption.equals(XFAME_OPTION_ALLOW_FROM) - ? new XFrameOptionsHeaderWriter(new StaticAllowFromStrategy(new URI(confAllowFromUri))) - : new XFrameOptionsHeaderWriter(xframeOptionFromStr(confXframeOption))) - .contentTypeOptions().xssProtection().httpStrictTransportSecurity().and() + httpSec // UI .authorizeRequests().antMatchers("/UI/login/**").permitAll().antMatchers("/UI/UIDL/**").permitAll() .anyRequest().authenticated().and() @@ -445,29 +411,6 @@ public class SecurityManagedConfiguration { .and().logout().logoutUrl("/UI/logout").logoutSuccessUrl("/UI/login/#/"); } - /** - * Converts a given string into the {@link XFrameOptionsMode} enum. Only - * {@link XFrameOptionsMode#DENY} and - * {@link XFrameOptionsMode#SAMEORIGIN} any other string will be - * converted to the default {@link XFrameOptionsMode#SAMEORIGIN}. - * - * @param xframeOption - * the string of the xframe option - * @return an {@link XFrameOptionsMode} by the given string, in case - * string does not match an option then - * {@link XFrameOptionsMode#SAMEORIGIN} is returned - */ - private static XFrameOptionsMode xframeOptionFromStr(@NotNull final String xframeOption) { - switch (xframeOption) { - case XFRAME_OPTION_DENY: - return XFrameOptionsMode.DENY; - case XFRAME_OPTION_SAMEORIGIN: - // fall through to default because the same - default: - return XFrameOptionsMode.SAMEORIGIN; - } - } - @Override public void configure(final WebSecurity webSecurity) throws Exception { webSecurity.ignoring().antMatchers("/documentation/**", "/VAADIN/**", "/*.*", "/v2/api-docs/**", diff --git a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactDownloadTest.java b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactDownloadTest.java index 7f12b78ae..d8931ab41 100644 --- a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactDownloadTest.java +++ b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactDownloadTest.java @@ -21,20 +21,24 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.nio.charset.StandardCharsets; +import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Arrays; +import java.util.Date; import java.util.List; +import java.util.TimeZone; import org.apache.commons.lang3.RandomUtils; import org.eclipse.hawkbit.eventbus.event.DownloadProgressEvent; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.Status; -import org.eclipse.hawkbit.repository.test.util.WithUser; import org.eclipse.hawkbit.repository.model.Artifact; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.LocalArtifact; import org.eclipse.hawkbit.repository.model.Target; +import org.eclipse.hawkbit.repository.test.util.WithUser; import org.eclipse.hawkbit.rest.AbstractRestIntegrationTestWithMongoDB; +import org.junit.Before; import org.junit.Test; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -65,6 +69,13 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong private volatile int downLoadProgress = 0; + private final SimpleDateFormat dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz"); + + @Before + public void setup() { + dateFormat.setTimeZone(TimeZone.getTimeZone("GMT")); + } + @Autowired private EventBus eventBus; @@ -267,7 +278,7 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong ds.findFirstModuleByType(osType).getId(), artifact.getFilename())) .andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_OCTET_STREAM)) .andExpect(header().string("Accept-Ranges", "bytes")) - .andExpect(header().longValue("Last-Modified", artifact.getCreatedAt())) + .andExpect(header().string("Last-Modified", dateFormat.format(new Date(artifact.getCreatedAt())))) .andExpect(header().string("Content-Disposition", "attachment;filename=" + artifact.getFilename())) .andReturn(); @@ -372,7 +383,7 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong .andExpect(status().isOk()).andExpect(header().string("ETag", artifact.getSha1Hash())) .andExpect(content().contentType(MediaType.APPLICATION_OCTET_STREAM)) .andExpect(header().string("Accept-Ranges", "bytes")) - .andExpect(header().longValue("Last-Modified", artifact.getCreatedAt())) + .andExpect(header().string("Last-Modified", dateFormat.format(new Date(artifact.getCreatedAt())))) .andExpect(header().string("Content-Disposition", "attachment;filename=file1")).andReturn(); assertTrue("The same file that was uploaded is expected when downloaded", @@ -429,7 +440,7 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong .andExpect(status().isPartialContent()).andExpect(header().string("ETag", artifact.getSha1Hash())) .andExpect(content().contentType(MediaType.APPLICATION_OCTET_STREAM)) .andExpect(header().string("Accept-Ranges", "bytes")) - .andExpect(header().longValue("Last-Modified", artifact.getCreatedAt())) + .andExpect(header().string("Last-Modified", dateFormat.format(new Date(artifact.getCreatedAt())))) .andExpect(header().longValue("Content-Length", range)) .andExpect(header().string("Content-Range", "bytes " + rangeString + "/" + resultLength)) .andExpect(header().string("Content-Disposition", "attachment;filename=file1")).andReturn(); @@ -446,7 +457,7 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong .andExpect(status().isPartialContent()).andExpect(header().string("ETag", artifact.getSha1Hash())) .andExpect(content().contentType(MediaType.APPLICATION_OCTET_STREAM)) .andExpect(header().string("Accept-Ranges", "bytes")) - .andExpect(header().longValue("Last-Modified", artifact.getCreatedAt())) + .andExpect(header().string("Last-Modified", dateFormat.format(new Date(artifact.getCreatedAt())))) .andExpect(header().longValue("Content-Length", 1000)) .andExpect(header().string("Content-Range", "bytes " + (resultLength - 1000) + "-" + (resultLength - 1) + "/" + resultLength)) @@ -462,7 +473,7 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong .andExpect(status().isPartialContent()).andExpect(header().string("ETag", artifact.getSha1Hash())) .andExpect(content().contentType(MediaType.APPLICATION_OCTET_STREAM)) .andExpect(header().string("Accept-Ranges", "bytes")) - .andExpect(header().longValue("Last-Modified", artifact.getCreatedAt())) + .andExpect(header().string("Last-Modified", dateFormat.format(new Date(artifact.getCreatedAt())))) .andExpect(header().longValue("Content-Length", resultLength - 1000)) .andExpect(header().string("Content-Range", "bytes " + 1000 + "-" + (resultLength - 1) + "/" + resultLength)) @@ -478,7 +489,7 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong .andExpect(status().isPartialContent()).andExpect(header().string("ETag", artifact.getSha1Hash())) .andExpect(content().contentType("multipart/byteranges; boundary=THIS_STRING_SEPARATES_MULTIPART")) .andExpect(header().string("Accept-Ranges", "bytes")) - .andExpect(header().longValue("Last-Modified", artifact.getCreatedAt())) + .andExpect(header().string("Last-Modified", dateFormat.format(new Date(artifact.getCreatedAt())))) .andExpect(header().string("Content-Disposition", "attachment;filename=file1")).andReturn(); outputStream.reset(); diff --git a/hawkbit-ddi-resource/src/test/resources/logback.xml b/hawkbit-ddi-resource/src/test/resources/logback-spring.xml similarity index 79% rename from hawkbit-ddi-resource/src/test/resources/logback.xml rename to hawkbit-ddi-resource/src/test/resources/logback-spring.xml index 447712338..c5d0969e1 100644 --- a/hawkbit-ddi-resource/src/test/resources/logback.xml +++ b/hawkbit-ddi-resource/src/test/resources/logback-spring.xml @@ -12,10 +12,10 @@ - + - + \ No newline at end of file diff --git a/hawkbit-dmf-amqp/src/test/resources/logback.xml b/hawkbit-dmf-amqp/src/test/resources/logback-spring.xml similarity index 97% rename from hawkbit-dmf-amqp/src/test/resources/logback.xml rename to hawkbit-dmf-amqp/src/test/resources/logback-spring.xml index 30060d1c6..6dd6c94e0 100644 --- a/hawkbit-dmf-amqp/src/test/resources/logback.xml +++ b/hawkbit-dmf-amqp/src/test/resources/logback-spring.xml @@ -29,7 +29,7 @@ - + \ No newline at end of file diff --git a/hawkbit-http-security/src/main/java/org/eclipse/hawkbit/security/AbstractHttpControllerAuthenticationFilter.java b/hawkbit-http-security/src/main/java/org/eclipse/hawkbit/security/AbstractHttpControllerAuthenticationFilter.java index 0e67489ea..48e54eca1 100644 --- a/hawkbit-http-security/src/main/java/org/eclipse/hawkbit/security/AbstractHttpControllerAuthenticationFilter.java +++ b/hawkbit-http-security/src/main/java/org/eclipse/hawkbit/security/AbstractHttpControllerAuthenticationFilter.java @@ -113,7 +113,7 @@ public abstract class AbstractHttpControllerAuthenticationFilter extends Abstrac @Override protected void successfulAuthentication(final HttpServletRequest request, final HttpServletResponse response, - final Authentication authResult) { + final Authentication authResult) throws IOException, ServletException { final Collection authorities = new ArrayList<>(); authorities.addAll(authResult.getAuthorities()); authorities.addAll(abstractControllerAuthenticationFilter.getSuccessfulAuthenticationAuthorities()); diff --git a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/SMRessourceMisingMongoDbConnectionTest.java b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/SMRessourceMisingMongoDbConnectionTest.java index de0411006..737bf50d5 100644 --- a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/SMRessourceMisingMongoDbConnectionTest.java +++ b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/SMRessourceMisingMongoDbConnectionTest.java @@ -15,10 +15,10 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. import org.apache.commons.lang3.RandomStringUtils; import org.eclipse.hawkbit.exception.SpServerError; import org.eclipse.hawkbit.repository.model.SoftwareModule; -import org.eclipse.hawkbit.rest.AbstractRestIntegrationTest; +import org.eclipse.hawkbit.rest.AbstractRestIntegrationTestWithMongoDB; import org.eclipse.hawkbit.rest.json.model.ExceptionInfo; import org.eclipse.hawkbit.rest.util.MockMvcResultPrinter; -import org.junit.BeforeClass; +import org.junit.After; import org.junit.Test; import org.springframework.mock.web.MockMultipartFile; import org.springframework.test.web.servlet.MvcResult; @@ -34,23 +34,17 @@ import ru.yandex.qatools.allure.annotations.Stories; */ @Features("Component Tests - Management API") @Stories("Download Resource") -public class SMRessourceMisingMongoDbConnectionTest extends AbstractRestIntegrationTest { - - @BeforeClass - public static void initialize() { - // set property to mongoPort which does not start any mongoDB of - // parallel test execution - System.setProperty("spring.data.mongodb.port", "1020"); - } +public class SMRessourceMisingMongoDbConnectionTest extends AbstractRestIntegrationTestWithMongoDB { @Test @Description("Ensures that the correct error code is returned in case MongoDB unavailable.") public void missingMongoDbConnectionResultsInErrorAtUpload() throws Exception { + mongodExecutable.stop(); assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(0); assertThat(artifactManagement.countLocalArtifactsAll()).isEqualTo(0); - SoftwareModule sm = entityFactory.generateSoftwareModule( - softwareManagement.findSoftwareModuleTypeByKey("os"), "name 1", "version 1", null, null); + SoftwareModule sm = entityFactory.generateSoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), + "name 1", "version 1", null, null); sm = softwareManagement.createSoftwareModule(sm); assertThat(artifactManagement.countLocalArtifactsAll()).isEqualTo(0); @@ -74,4 +68,9 @@ public class SMRessourceMisingMongoDbConnectionTest extends AbstractRestIntegrat } + @After + public void cleanCurrentCollection() { + // not needed, mongodb is stopped already + } + } diff --git a/hawkbit-mgmt-resource/src/test/resources/logback.xml b/hawkbit-mgmt-resource/src/test/resources/logback-spring.xml similarity index 97% rename from hawkbit-mgmt-resource/src/test/resources/logback.xml rename to hawkbit-mgmt-resource/src/test/resources/logback-spring.xml index 30060d1c6..6dd6c94e0 100644 --- a/hawkbit-mgmt-resource/src/test/resources/logback.xml +++ b/hawkbit-mgmt-resource/src/test/resources/logback-spring.xml @@ -29,7 +29,7 @@ - + \ No newline at end of file diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ArtifactManagementFailedMongoDBTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ArtifactManagementFailedMongoDBTest.java new file mode 100644 index 000000000..98af08494 --- /dev/null +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ArtifactManagementFailedMongoDBTest.java @@ -0,0 +1,74 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.jpa; + +import static org.fest.assertions.api.Assertions.assertThat; +import static org.junit.Assert.fail; + +import java.io.IOException; +import java.net.UnknownHostException; + +import org.eclipse.hawkbit.repository.exception.ArtifactDeleteFailedException; +import org.eclipse.hawkbit.repository.exception.ArtifactUploadFailedException; +import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule; +import org.eclipse.hawkbit.repository.model.Artifact; +import org.junit.After; +import org.junit.Test; + +import ru.yandex.qatools.allure.annotations.Description; +import ru.yandex.qatools.allure.annotations.Features; +import ru.yandex.qatools.allure.annotations.Stories; + +@Features("Component Tests - Repository") +@Stories("Artifact Management") +public class ArtifactManagementFailedMongoDBTest extends AbstractJpaIntegrationTestWithMongoDB { + + @Test + @Description("Trys and fails to delete or create local artifact with a down mongodb and checks if expected ArtifactDeleteFailedException is thrown.") + public void deleteArtifactsWithNoMongoDb() throws UnknownHostException, IOException { + // ensure baseline + assertThat(artifactRepository.findAll()).isEmpty(); + + // prepare test + JpaSoftwareModule sm = new JpaSoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), "name 1", + "version 1", null, null); + sm = softwareModuleRepository.save(sm); + + final Artifact result = artifactManagement.createLocalArtifact(new RandomGeneratedInputStream(5 * 1024), + sm.getId(), "file1", false); + + assertThat(artifactRepository.findAll()).hasSize(1); + + mongodExecutable.stop(); + try { + artifactManagement.deleteLocalArtifact(result.getId()); + fail("deletion should have failed"); + } catch (final ArtifactDeleteFailedException e) { + + } + + try { + artifactManagement.createLocalArtifact(new RandomGeneratedInputStream(5 * 1024), sm.getId(), "file2", + false); + fail("Should not have worked with MongoDb down."); + } catch (final ArtifactUploadFailedException e) { + + } + + assertThat(artifactRepository.findAll()).hasSize(1); + + } + + @Override + @After + public void cleanCurrentCollection() { + // no need to clean, is stopped already + } + +} diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ArtifactManagementNoMongoDbTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ArtifactManagementNoMongoDbTest.java deleted file mode 100644 index 42b759b74..000000000 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ArtifactManagementNoMongoDbTest.java +++ /dev/null @@ -1,58 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.repository.jpa; - -import static org.junit.Assert.fail; - -import java.io.ByteArrayInputStream; -import java.io.IOException; - -import org.apache.commons.lang3.RandomStringUtils; -import org.eclipse.hawkbit.repository.exception.ArtifactUploadFailedException; -import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule; -import org.junit.BeforeClass; -import org.junit.Test; - -import ru.yandex.qatools.allure.annotations.Description; -import ru.yandex.qatools.allure.annotations.Features; -import ru.yandex.qatools.allure.annotations.Stories; - -/** - * Addition tests next to {@link ArtifactManagementTest} with no running MongoDB - * - */ -@Features("Component Tests - Repository") -@Stories("Artifact Management") -public class ArtifactManagementNoMongoDbTest extends AbstractJpaIntegrationTest { - - @BeforeClass - public static void initialize() { - // set property to mongoPort which does not start any mongoDB of - // parallel test execution - System.setProperty("spring.data.mongodb.port", "1020"); - } - - @Test - @Description("Checks if the expected ArtifactUploadFailedException is thrown in case of MongoDB down") - public void createLocalArtifactWithMongoDbDown() throws IOException { - JpaSoftwareModule sm = new JpaSoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), "name 1", - "version 1", null, null); - sm = softwareModuleRepository.save(sm); - - final byte random[] = RandomStringUtils.random(5 * 1024).getBytes(); - - try { - artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), sm.getId(), "file1", false); - fail("Should not have worked with MongoDb down."); - } catch (final ArtifactUploadFailedException e) { - - } - } - -} diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ArtifactManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ArtifactManagementTest.java index 293dcdf91..ac12ff4f9 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ArtifactManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ArtifactManagementTest.java @@ -15,14 +15,12 @@ import static org.junit.Assert.fail; import java.io.ByteArrayInputStream; import java.io.IOException; -import java.net.UnknownHostException; import java.security.NoSuchAlgorithmException; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.RandomStringUtils; import org.eclipse.hawkbit.im.authentication.SpPermission; import org.eclipse.hawkbit.repository.ArtifactManagement; -import org.eclipse.hawkbit.repository.exception.ArtifactDeleteFailedException; import org.eclipse.hawkbit.repository.exception.InsufficientPermissionException; import org.eclipse.hawkbit.repository.jpa.model.JpaExternalArtifact; import org.eclipse.hawkbit.repository.jpa.model.JpaExternalArtifactProvider; @@ -241,36 +239,6 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTestWithMongoD assertThat(artifactRepository.findAll()).hasSize(0); } - @Test - @Description("Trys and fails to delete local artifact with a down mongodb and checks if expected ArtifactDeleteFailedException is thrown.") - public void deleteArtifactsWithNoMongoDb() throws UnknownHostException, IOException { - // ensure baseline - assertThat(artifactRepository.findAll()).isEmpty(); - - // prepare test - JpaSoftwareModule sm = new JpaSoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), "name 1", - "version 1", null, null); - sm = softwareModuleRepository.save(sm); - - final Artifact result = artifactManagement.createLocalArtifact(new RandomGeneratedInputStream(5 * 1024), - sm.getId(), "file1", false); - - assertThat(artifactRepository.findAll()).hasSize(1); - - internalShutDownMongo(); - try { - artifactManagement.deleteLocalArtifact(result.getId()); - fail("deletion should have failed"); - } catch (final ArtifactDeleteFailedException e) { - - } - setupMongo(); - - assertThat(artifactRepository.findAll()).hasSize(1); - assertThat(artifactManagement.findArtifact(result.getId())).isEqualTo(result); - - } - @Test @Description("Test the deletion of an artifact metadata where the binary is still linked to another " + "metadata element. The expected result is that the metadata is deleted but the binary kept.") diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/resources/logback-spring.xml b/hawkbit-repository/hawkbit-repository-jpa/src/test/resources/logback-spring.xml new file mode 100644 index 000000000..4a7755609 --- /dev/null +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/resources/logback-spring.xml @@ -0,0 +1,19 @@ + + + + + + + + + + \ No newline at end of file diff --git a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/AbstractIntegrationTest.java b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/AbstractIntegrationTest.java index 3d09fabc3..2272d74ea 100644 --- a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/AbstractIntegrationTest.java +++ b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/AbstractIntegrationTest.java @@ -48,6 +48,7 @@ import org.springframework.data.domain.Pageable; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext.ClassMode; import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.test.web.servlet.MockMvc; @@ -65,6 +66,7 @@ import org.springframework.web.context.WebApplicationContext; // refreshed we e.g. get two instances of CacheManager which leads to very // strange test failures. @DirtiesContext(classMode = ClassMode.AFTER_CLASS) +@TestPropertySource(properties = { "spring.data.mongodb.port=0", "spring.mongodb.embedded.version=3.2.7" }) public abstract class AbstractIntegrationTest implements EnvironmentAware { protected static Logger LOG = null; diff --git a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/AbstractIntegrationTestWithMongoDB.java b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/AbstractIntegrationTestWithMongoDB.java index bb54f550c..589cac381 100644 --- a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/AbstractIntegrationTestWithMongoDB.java +++ b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/AbstractIntegrationTestWithMongoDB.java @@ -8,103 +8,27 @@ */ package org.eclipse.hawkbit.repository.test.util; -import java.io.IOException; -import java.net.UnknownHostException; -import java.util.concurrent.atomic.AtomicInteger; - import org.junit.After; -import org.junit.AfterClass; -import org.junit.BeforeClass; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.mongodb.core.query.Query; import org.springframework.data.mongodb.gridfs.GridFsOperations; -import de.flapdoodle.embed.mongo.Command; import de.flapdoodle.embed.mongo.MongodExecutable; -import de.flapdoodle.embed.mongo.MongodStarter; -import de.flapdoodle.embed.mongo.config.ArtifactStoreBuilder; -import de.flapdoodle.embed.mongo.config.DownloadConfigBuilder; -import de.flapdoodle.embed.mongo.config.IMongodConfig; -import de.flapdoodle.embed.mongo.config.MongodConfigBuilder; -import de.flapdoodle.embed.mongo.config.Net; -import de.flapdoodle.embed.mongo.config.RuntimeConfigBuilder; -import de.flapdoodle.embed.mongo.distribution.Version; -import de.flapdoodle.embed.process.config.store.HttpProxyFactory; -import de.flapdoodle.embed.process.runtime.Network; /** - * Test class that contains MonfoDb start and stop for the test - * - * - * - * + * Test class that contains embedded MongoDB for the test. */ public abstract class AbstractIntegrationTestWithMongoDB extends AbstractIntegrationTest { - protected static volatile MongodExecutable mongodExecutable = null; - private static final AtomicInteger mongoLease = new AtomicInteger(0); - private static volatile Integer port; - @Autowired protected GridFsOperations operations; - @BeforeClass - public static void setupMongo() throws UnknownHostException, IOException { - mongoLease.incrementAndGet(); - if (mongodExecutable == null) { - final Command command = Command.MongoD; - - final RuntimeConfigBuilder runtimeConfig = new RuntimeConfigBuilder().defaults(command); - - if (port == null) { - port = new FreePortFileWriter(28017, 28090, "./target/freeports").getPort(); - System.setProperty("spring.data.mongodb.port", String.valueOf(port)); - } - - Version version = Version.V3_0_8; - if (System.getProperty("inf.mongodb.version") != null) { - version = Version - .valueOf("V" + System.getProperty("inf.mongodb.version").trim().replaceAll("\\.", "_")); - } - - if (System.getProperty("http.proxyHost") != null) { - runtimeConfig - .artifactStore( - new ArtifactStoreBuilder().defaults(command) - .download(new DownloadConfigBuilder().defaultsForCommand(command) - .proxyFactory(new HttpProxyFactory( - System.getProperty("http.proxyHost").trim(), Integer - .valueOf(System.getProperty("http.proxyPort")))))); - } - - final IMongodConfig mongodConfig = new MongodConfigBuilder().version(version) - .net(new Net("127.0.0.1", port, Network.localhostIsIPv6())).build(); - - final MongodStarter starter = MongodStarter.getInstance(runtimeConfig.build()); - mongodExecutable = starter.prepare(mongodConfig); - mongodExecutable.start(); - } - - } + @Autowired + protected MongodExecutable mongodExecutable; @After public void cleanCurrentCollection() { operations.delete(new Query()); } - public static void internalShutDownMongo() { - if (mongodExecutable != null && mongoLease.decrementAndGet() <= 0) { - mongodExecutable.stop(); - mongodExecutable = null; - } - } - - @AfterClass - public static void shutdownMongo() throws UnknownHostException, IOException { - if (mongodExecutable != null && mongoLease.decrementAndGet() <= 0) { - mongodExecutable.stop(); - mongodExecutable = null; - } - port = null; - } } diff --git a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/FreePortFileWriter.java b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/FreePortFileWriter.java deleted file mode 100644 index 149cdf2b5..000000000 --- a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/FreePortFileWriter.java +++ /dev/null @@ -1,75 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.repository.test.util; - -import java.io.File; -import java.net.InetSocketAddress; -import java.net.ServerSocket; - -/** - * - * - */ -public class FreePortFileWriter { - - private final String filePortPath; - private final int from; - private final int to; - - /** - * @param from - * @param to - */ - public FreePortFileWriter(final int from, final int to, final String filePortPath) { - this.from = from; - this.to = to; - this.filePortPath = filePortPath; - } - - public int getPort() { - return findFree(); - } - - protected int findFree() { - for (int i = from; i <= to; i++) { - if (isFree(i)) { - return i; - } - } - throw new RuntimeException("No free port in range " + from + ":" + to); - } - - boolean isFree(final int port) { - try { - final File portFile = new File(filePortPath + File.separator + port + ".port"); - portFile.getParentFile().mkdirs(); - if (portFile.exists()) { - return false; - } else { - boolean isFree = false; - final ServerSocket sock = new ServerSocket(); - sock.setReuseAddress(true); - sock.bind(new InetSocketAddress(port)); - if (portFile.createNewFile()) { - portFile.deleteOnExit(); - isFree = true; - } - sock.close(); - // is free: - return isFree; - // We rely on an exception thrown to determine availability or - // not availability. - } - } catch (final Exception e) { - // not free. - return false; - } - } - -} diff --git a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/TestConfiguration.java b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/TestConfiguration.java index 3a7a2f73d..dbdc0db82 100644 --- a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/TestConfiguration.java +++ b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/TestConfiguration.java @@ -45,11 +45,10 @@ import com.mongodb.MongoClientOptions; * */ @Configuration -@EnableGlobalMethodSecurity(prePostEnabled = true, mode = AdviceMode.ASPECTJ, proxyTargetClass = true, securedEnabled = true) +@EnableGlobalMethodSecurity(prePostEnabled = true, mode = AdviceMode.PROXY, proxyTargetClass = false, securedEnabled = true) @EnableConfigurationProperties({ HawkbitServerProperties.class, DdiSecurityProperties.class }) @Profile("test") public class TestConfiguration implements AsyncConfigurer { - @Bean public TestRepositoryManagement testRepositoryManagement() { return new JpaTestRepositoryManagement(); diff --git a/hawkbit-security-core/src/main/java/org/eclipse/hawkbit/im/authentication/SpPermission.java b/hawkbit-security-core/src/main/java/org/eclipse/hawkbit/im/authentication/SpPermission.java index 139954538..6a68aee5b 100644 --- a/hawkbit-security-core/src/main/java/org/eclipse/hawkbit/im/authentication/SpPermission.java +++ b/hawkbit-security-core/src/main/java/org/eclipse/hawkbit/im/authentication/SpPermission.java @@ -378,8 +378,7 @@ public final class SpPermission { * {@link SpPermission#READ_TARGET} */ public static final String HAS_AUTH_ROLLOUT_MANAGEMENT_READ_AND_TARGET_READ = HAS_AUTH_PREFIX - + ROLLOUT_MANAGEMENT + HAS_AUTH_SUFFIX + HAS_AUTH_AND + HAS_AUTH_PREFIX + READ_TARGET - + HAS_AUTH_SUFFIX;; + + ROLLOUT_MANAGEMENT + HAS_AUTH_SUFFIX + HAS_AUTH_AND + HAS_AUTH_PREFIX + READ_TARGET + HAS_AUTH_SUFFIX; /** * Spring security eval hasAuthority expression to check if spring diff --git a/hawkbit-security-core/src/main/java/org/eclipse/hawkbit/security/HawkbitSecurityProperties.java b/hawkbit-security-core/src/main/java/org/eclipse/hawkbit/security/HawkbitSecurityProperties.java index 3f0be994a..d6de1f80e 100644 --- a/hawkbit-security-core/src/main/java/org/eclipse/hawkbit/security/HawkbitSecurityProperties.java +++ b/hawkbit-security-core/src/main/java/org/eclipse/hawkbit/security/HawkbitSecurityProperties.java @@ -21,7 +21,6 @@ public class HawkbitSecurityProperties { private final Clients clients = new Clients(); private final Dos dos = new Dos(); - private final Xframe xframe = new Xframe(); public Dos getDos() { return dos; @@ -31,45 +30,6 @@ public class HawkbitSecurityProperties { return clients; } - public Xframe getXframe() { - return xframe; - } - - /** - * Defines the XFrameOption policy. - * - */ - public static class Xframe { - - /** - * XFrame option. Allowed values: SAMEORIGIN, DENY, ALLOW-FROM - */ - private String option = "DENY"; - - /** - * ALLOW-FROM defined URL, has to be filled in case ALLOW-FROM option is - * selected. - */ - private String allowfrom = ""; - - public String getOption() { - return option; - } - - public void setOption(final String option) { - this.option = option; - } - - public String getAllowfrom() { - return allowfrom; - } - - public void setAllowfrom(final String allowfrom) { - this.allowfrom = allowfrom; - } - - } - /** * Security configuration related to clients. * diff --git a/pom.xml b/pom.xml index 444883bba..e6ae80162 100644 --- a/pom.xml +++ b/pom.xml @@ -14,7 +14,7 @@ org.springframework.boot spring-boot-starter-parent - 1.2.8.RELEASE + 1.3.6.RELEASE org.eclipse.hawkbit @@ -61,18 +61,15 @@ 1.8 - 1.2.8.RELEASE + 1.3.6.RELEASE - 2.5.5 - 5.2.4.Final 1.2.0.RELEASE 1.6.0.RELEASE 3.6.2 - 0.18.0.RELEASE + 4.1.0.RELEASE - Fowler-SR1 3.2.2 @@ -104,7 +101,7 @@ 1.8.5 19.0 1.4.3 - 1.50.2 + 1.50.5 1.18.1 2.2.4 1.1.7 @@ -486,11 +483,6 @@ spring-boot-starter-websocket ${spring.boot.version} - - org.springframework.boot - spring-boot-starter-cloud-connectors - ${spring.boot.version} - org.springframework.boot spring-boot-starter-aop From e285495c885a8fdcbabd44fb3b6b1c48646380c1 Mon Sep 17 00:00:00 2001 From: kaizimmerm Date: Mon, 11 Jul 2016 12:24:33 +0200 Subject: [PATCH 02/24] Fixed tests. Signed-off-by: kaizimmerm --- .../mgmt/rest/resource/MgmtTargetResourceTest.java | 4 ++-- .../hawkbit/rest/configuration/RestConfiguration.java | 3 +++ pom.xml | 9 +-------- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResourceTest.java b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResourceTest.java index a528438bb..3cb9222aa 100644 --- a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResourceTest.java +++ b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResourceTest.java @@ -139,10 +139,10 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest { public void securityTokenIsNotInResponseIfMissingPermission() throws Exception { final String knownControllerId = "knownControllerId"; - targetManagement.createTarget(entityFactory.generateTarget(knownControllerId)); + final Target createTarget = targetManagement.createTarget(entityFactory.generateTarget(knownControllerId)); mvc.perform(get(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/{targetId}", knownControllerId)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) - .andExpect(jsonPath("securityToken").doesNotExist()); + .andExpect(jsonPath("securityToken", equalTo(null))); } @Test diff --git a/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/configuration/RestConfiguration.java b/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/configuration/RestConfiguration.java index e2c4ec2a1..73f7eed76 100644 --- a/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/configuration/RestConfiguration.java +++ b/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/configuration/RestConfiguration.java @@ -17,12 +17,15 @@ import org.springframework.beans.factory.FactoryBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Scope; +import org.springframework.hateoas.config.EnableHypermediaSupport; +import org.springframework.hateoas.config.EnableHypermediaSupport.HypermediaType; import org.springframework.web.context.WebApplicationContext; /** * Configuration for Rest api. */ @Configuration +@EnableHypermediaSupport(type = { HypermediaType.HAL }) public class RestConfiguration { /** diff --git a/pom.xml b/pom.xml index e6ae80162..3db7372df 100644 --- a/pom.xml +++ b/pom.xml @@ -68,7 +68,7 @@ 1.2.0.RELEASE 1.6.0.RELEASE 3.6.2 - 4.1.0.RELEASE + 4.1.1.RELEASE 3.2.2 @@ -102,7 +102,6 @@ 19.0 1.4.3 1.50.5 - 1.18.1 2.2.4 1.1.7 1.1 @@ -591,12 +590,6 @@ ${allure.version} test - - com.sun.jersey - jersey-client - ${jersey-client.version} - test - pl.pragmatists JUnitParams From 624d9491d0ba6c3b09310d66b3b65ef386548695 Mon Sep 17 00:00:00 2001 From: kaizimmerm Date: Sat, 16 Jul 2016 20:17:44 +0200 Subject: [PATCH 03/24] Removed enable auto configure from repo config Signed-off-by: kaizimmerm --- .../hawkbit/RepositoryApplicationConfiguration.java | 2 -- .../{repository/test/util => }/TestConfiguration.java | 8 ++++++-- .../repository/test/util/AbstractIntegrationTest.java | 1 + 3 files changed, 7 insertions(+), 4 deletions(-) rename hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/{repository/test/util => }/TestConfiguration.java (92%) diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/RepositoryApplicationConfiguration.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/RepositoryApplicationConfiguration.java index 217fe8801..c159bdc6b 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/RepositoryApplicationConfiguration.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/RepositoryApplicationConfiguration.java @@ -54,7 +54,6 @@ import org.eclipse.hawkbit.repository.jpa.model.helper.TenantConfigurationManage import org.eclipse.hawkbit.security.SecurityTokenGenerator; import org.eclipse.hawkbit.security.SystemSecurityContext; import org.eclipse.hawkbit.tenancy.TenantAware; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration; import org.springframework.boot.context.properties.EnableConfigurationProperties; @@ -81,7 +80,6 @@ import org.springframework.validation.beanvalidation.MethodValidationPostProcess @EnableAspectJAutoProxy @Configuration @ComponentScan -@EnableAutoConfiguration @EnableConfigurationProperties(RepositoryProperties.class) @EnableScheduling public class RepositoryApplicationConfiguration extends JpaBaseConfiguration { diff --git a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/TestConfiguration.java b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/TestConfiguration.java similarity index 92% rename from hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/TestConfiguration.java rename to hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/TestConfiguration.java index dbdc0db82..499925540 100644 --- a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/TestConfiguration.java +++ b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/TestConfiguration.java @@ -6,22 +6,25 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository.test.util; +package org.eclipse.hawkbit; import java.util.concurrent.Executor; import java.util.concurrent.Executors; -import org.eclipse.hawkbit.HawkbitServerProperties; import org.eclipse.hawkbit.cache.CacheConstants; import org.eclipse.hawkbit.cache.TenancyCacheManager; import org.eclipse.hawkbit.cache.TenantAwareCacheManager; import org.eclipse.hawkbit.repository.jpa.model.helper.EventBusHolder; +import org.eclipse.hawkbit.repository.test.util.JpaTestRepositoryManagement; +import org.eclipse.hawkbit.repository.test.util.TestRepositoryManagement; +import org.eclipse.hawkbit.repository.test.util.TestdataFactory; import org.eclipse.hawkbit.security.DdiSecurityProperties; import org.eclipse.hawkbit.security.SecurityContextTenantAware; import org.eclipse.hawkbit.security.SpringSecurityAuditorAware; import org.eclipse.hawkbit.tenancy.TenantAware; import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler; import org.springframework.aop.interceptor.SimpleAsyncUncaughtExceptionHandler; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.cache.Cache; import org.springframework.cache.guava.GuavaCacheManager; @@ -48,6 +51,7 @@ import com.mongodb.MongoClientOptions; @EnableGlobalMethodSecurity(prePostEnabled = true, mode = AdviceMode.PROXY, proxyTargetClass = false, securedEnabled = true) @EnableConfigurationProperties({ HawkbitServerProperties.class, DdiSecurityProperties.class }) @Profile("test") +@EnableAutoConfiguration public class TestConfiguration implements AsyncConfigurer { @Bean public TestRepositoryManagement testRepositoryManagement() { diff --git a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/AbstractIntegrationTest.java b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/AbstractIntegrationTest.java index 2272d74ea..081cedeca 100644 --- a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/AbstractIntegrationTest.java +++ b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/AbstractIntegrationTest.java @@ -9,6 +9,7 @@ package org.eclipse.hawkbit.repository.test.util; import org.eclipse.hawkbit.ExcludePathAwareShallowETagFilter; +import org.eclipse.hawkbit.TestConfiguration; import org.eclipse.hawkbit.repository.ArtifactManagement; import org.eclipse.hawkbit.repository.ControllerManagement; import org.eclipse.hawkbit.repository.DeploymentManagement; From 2e416d00275804157446ae50b5209446a2ce45d6 Mon Sep 17 00:00:00 2001 From: kaizimmerm Date: Thu, 21 Jul 2016 10:39:57 +0200 Subject: [PATCH 04/24] Using same plugin for weave and metamodel Signed-off-by: kaizimmerm --- .../hawkbit-repository-jpa/pom.xml | 53 ++++++------------- 1 file changed, 15 insertions(+), 38 deletions(-) diff --git a/hawkbit-repository/hawkbit-repository-jpa/pom.xml b/hawkbit-repository/hawkbit-repository-jpa/pom.xml index bd56e9ca5..24c90e28e 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/pom.xml +++ b/hawkbit-repository/hawkbit-repository-jpa/pom.xml @@ -1,14 +1,9 @@ - - + + 4.0.0 org.eclipse.hawkbit @@ -120,7 +115,7 @@ javax.el javax.el-api test - + ru.yandex.qatools.allure allure-junit-adaptor @@ -140,43 +135,25 @@ - - org.bsc.maven - maven-processor-plugin - - - process - - process - - generate-sources - - - org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor - - - - - - - org.hibernate - hibernate-jpamodelgen - ${hibernate.version} - - - com.ethlo.persistence.tools eclipselink-maven-plugin 2.6.2 + + modelgen + generate-sources + + modelgen + + process-classes weave - + From 99adab1a5fb357ae2c885262bba01329bc17400a Mon Sep 17 00:00:00 2001 From: kaizimmerm Date: Wed, 27 Jul 2016 14:51:18 +0200 Subject: [PATCH 05/24] Fixed license header and entity scan. Signed-off-by: kaizimmerm --- hawkbit-repository/hawkbit-repository-jpa/pom.xml | 14 ++++++++++---- .../RepositoryApplicationConfiguration.java | 2 ++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/hawkbit-repository/hawkbit-repository-jpa/pom.xml b/hawkbit-repository/hawkbit-repository-jpa/pom.xml index 24c90e28e..3646e97fc 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/pom.xml +++ b/hawkbit-repository/hawkbit-repository-jpa/pom.xml @@ -1,7 +1,13 @@ - + 4.0.0 diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/RepositoryApplicationConfiguration.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/RepositoryApplicationConfiguration.java index c159bdc6b..628af38e0 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/RepositoryApplicationConfiguration.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/RepositoryApplicationConfiguration.java @@ -57,6 +57,7 @@ import org.eclipse.hawkbit.tenancy.TenantAware; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration; import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.boot.orm.jpa.EntityScan; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; @@ -82,6 +83,7 @@ import org.springframework.validation.beanvalidation.MethodValidationPostProcess @ComponentScan @EnableConfigurationProperties(RepositoryProperties.class) @EnableScheduling +@EntityScan("org.eclipse.hawkbit.repository.jpa.model") public class RepositoryApplicationConfiguration extends JpaBaseConfiguration { /** * @return the {@link SystemSecurityContext} singleton bean which make it From 4b58d83e01e856bf1d4a24ab3da6b04e8919fc4b Mon Sep 17 00:00:00 2001 From: Kai Zimmermann Date: Thu, 18 Aug 2016 14:54:32 +0200 Subject: [PATCH 06/24] Upgarde boot and sec to newest patch version. Signed-off-by: Kai Zimmermann --- examples/hawkbit-example-app/pom.xml | 20 -------------------- pom.xml | 6 +++--- 2 files changed, 3 insertions(+), 23 deletions(-) diff --git a/examples/hawkbit-example-app/pom.xml b/examples/hawkbit-example-app/pom.xml index f501d5529..15d802792 100644 --- a/examples/hawkbit-example-app/pom.xml +++ b/examples/hawkbit-example-app/pom.xml @@ -107,26 +107,6 @@ org.springframework.boot spring-boot-starter - - - org.apache.logging.log4j - log4j-api - - - - org.slf4j - jul-to-slf4j - - - - org.slf4j - jcl-over-slf4j - - - - org.slf4j - log4j-over-slf4j - org.springframework.security spring-security-aspects diff --git a/pom.xml b/pom.xml index e8b402f17..5c4c4bd57 100644 --- a/pom.xml +++ b/pom.xml @@ -14,7 +14,7 @@ org.springframework.boot spring-boot-starter-parent - 1.3.6.RELEASE + 1.3.7.RELEASE org.eclipse.hawkbit @@ -61,13 +61,13 @@ 1.8 - 1.3.6.RELEASE + 1.3.7.RELEASE 1.2.0.RELEASE 1.6.1.RELEASE - 4.1.1.RELEASE + 4.1.2.RELEASE 3.2.2 From 276792d00568122a0d8e1f5a1347f9f219e78678 Mon Sep 17 00:00:00 2001 From: kaizimmerm Date: Fri, 19 Aug 2016 14:22:43 +0200 Subject: [PATCH 07/24] Fix simulator log config. Signed-off-by: kaizimmerm --- .../src/main/resources/{logback.xml => logback-spring.xml} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename examples/hawkbit-device-simulator/src/main/resources/{logback.xml => logback-spring.xml} (96%) diff --git a/examples/hawkbit-device-simulator/src/main/resources/logback.xml b/examples/hawkbit-device-simulator/src/main/resources/logback-spring.xml similarity index 96% rename from examples/hawkbit-device-simulator/src/main/resources/logback.xml rename to examples/hawkbit-device-simulator/src/main/resources/logback-spring.xml index 5f3f1dbef..355284d39 100644 --- a/examples/hawkbit-device-simulator/src/main/resources/logback.xml +++ b/examples/hawkbit-device-simulator/src/main/resources/logback-spring.xml @@ -22,7 +22,7 @@ - + \ No newline at end of file From ff500d3bd7a7634708248f921931fd6ecfe10760 Mon Sep 17 00:00:00 2001 From: kaizimmerm Date: Thu, 7 Jul 2016 12:39:40 +0200 Subject: [PATCH 08/24] Started migration for Boot 1.3 and Security 4.1 Signed-off-by: kaizimmerm --- .../{logback.xml => logback-spring.xml} | 2 +- .../{logback.xml => logback-spring.xml} | 6 +- .../ArtifactStoreAutoConfiguration.java | 2 - .../repository/MongoConfiguration.java | 119 -------- .../hawkbit/artifact/FreePortFileWriter.java | 78 ----- .../hawkbit/artifact/MongoDBTestRule.java | 115 -------- .../repository/ArtifactStoreTest.java | 7 +- .../SecurityManagedConfiguration.java | 61 +--- .../resource/DdiArtifactDownloadTest.java | 53 ++-- .../{logback.xml => logback-spring.xml} | 4 +- .../{logback.xml => logback-spring.xml} | 2 +- ...actHttpControllerAuthenticationFilter.java | 2 +- ...MRessourceMisingMongoDbConnectionTest.java | 23 +- .../{logback.xml => logback-spring.xml} | 2 +- .../ArtifactManagementFailedMongoDBTest.java | 74 +++++ .../jpa/ArtifactManagementNoMongoDbTest.java | 58 ---- .../jpa/ArtifactManagementTest.java | 32 -- .../src/test/resources/logback-spring.xml | 19 ++ .../test/util/AbstractIntegrationTest.java | 2 + .../AbstractIntegrationTestWithMongoDB.java | 82 +----- .../test/util/FreePortFileWriter.java | 73 ----- .../test/util/TestConfiguration.java | 3 +- .../im/authentication/SpPermission.java | 274 ++++++++---------- .../security/HawkbitSecurityProperties.java | 40 --- pom.xml | 10 +- 25 files changed, 265 insertions(+), 878 deletions(-) rename examples/hawkbit-example-app/src/main/resources/{logback.xml => logback-spring.xml} (96%) rename examples/hawkbit-example-mgmt-simulator/src/main/resources/{logback.xml => logback-spring.xml} (88%) delete mode 100644 hawkbit-artifact-repository-mongo/src/main/java/org/eclipse/hawkbit/artifact/repository/MongoConfiguration.java delete mode 100644 hawkbit-artifact-repository-mongo/src/test/java/org/eclipse/hawkbit/artifact/FreePortFileWriter.java delete mode 100644 hawkbit-artifact-repository-mongo/src/test/java/org/eclipse/hawkbit/artifact/MongoDBTestRule.java rename hawkbit-ddi-resource/src/test/resources/{logback.xml => logback-spring.xml} (79%) rename hawkbit-dmf-amqp/src/test/resources/{logback.xml => logback-spring.xml} (97%) rename hawkbit-mgmt-resource/src/test/resources/{logback.xml => logback-spring.xml} (97%) create mode 100644 hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ArtifactManagementFailedMongoDBTest.java delete mode 100644 hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ArtifactManagementNoMongoDbTest.java create mode 100644 hawkbit-repository/hawkbit-repository-jpa/src/test/resources/logback-spring.xml delete mode 100644 hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/FreePortFileWriter.java diff --git a/examples/hawkbit-example-app/src/main/resources/logback.xml b/examples/hawkbit-example-app/src/main/resources/logback-spring.xml similarity index 96% rename from examples/hawkbit-example-app/src/main/resources/logback.xml rename to examples/hawkbit-example-app/src/main/resources/logback-spring.xml index a76e39683..2f64ef001 100644 --- a/examples/hawkbit-example-app/src/main/resources/logback.xml +++ b/examples/hawkbit-example-app/src/main/resources/logback-spring.xml @@ -26,7 +26,7 @@ - + \ No newline at end of file diff --git a/examples/hawkbit-example-mgmt-simulator/src/main/resources/logback.xml b/examples/hawkbit-example-mgmt-simulator/src/main/resources/logback-spring.xml similarity index 88% rename from examples/hawkbit-example-mgmt-simulator/src/main/resources/logback.xml rename to examples/hawkbit-example-mgmt-simulator/src/main/resources/logback-spring.xml index 768f30687..765fdb869 100644 --- a/examples/hawkbit-example-mgmt-simulator/src/main/resources/logback.xml +++ b/examples/hawkbit-example-mgmt-simulator/src/main/resources/logback-spring.xml @@ -14,8 +14,8 @@ - - - + + + \ No newline at end of file diff --git a/hawkbit-artifact-repository-mongo/src/main/java/org/eclipse/hawkbit/artifact/repository/ArtifactStoreAutoConfiguration.java b/hawkbit-artifact-repository-mongo/src/main/java/org/eclipse/hawkbit/artifact/repository/ArtifactStoreAutoConfiguration.java index 8a1cb89a9..38df78dcb 100644 --- a/hawkbit-artifact-repository-mongo/src/main/java/org/eclipse/hawkbit/artifact/repository/ArtifactStoreAutoConfiguration.java +++ b/hawkbit-artifact-repository-mongo/src/main/java/org/eclipse/hawkbit/artifact/repository/ArtifactStoreAutoConfiguration.java @@ -11,14 +11,12 @@ package org.eclipse.hawkbit.artifact.repository; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Import; /** * Auto configuration for the {@link ArtifactStore}. */ @Configuration @ConditionalOnMissingBean(value = ArtifactRepository.class) -@Import(value = MongoConfiguration.class) public class ArtifactStoreAutoConfiguration { /** diff --git a/hawkbit-artifact-repository-mongo/src/main/java/org/eclipse/hawkbit/artifact/repository/MongoConfiguration.java b/hawkbit-artifact-repository-mongo/src/main/java/org/eclipse/hawkbit/artifact/repository/MongoConfiguration.java deleted file mode 100644 index e01c6a455..000000000 --- a/hawkbit-artifact-repository-mongo/src/main/java/org/eclipse/hawkbit/artifact/repository/MongoConfiguration.java +++ /dev/null @@ -1,119 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.artifact.repository; - -import java.net.UnknownHostException; -import java.util.Arrays; - -import javax.annotation.PreDestroy; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.boot.autoconfigure.mongo.MongoProperties; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Profile; -import org.springframework.data.mongodb.config.AbstractMongoConfiguration; - -import com.mongodb.Mongo; -import com.mongodb.MongoClient; -import com.mongodb.MongoClientOptions; -import com.mongodb.MongoClientOptions.Builder; -import com.mongodb.MongoClientURI; -import com.mongodb.ServerAddress; - -/** - * {@link AbstractMongoConfiguration} that uses {@link MongoClientURI} even when - * port is configured for NON {@link Cloud} use cases. - * - */ -@Configuration -@EnableConfigurationProperties(MongoProperties.class) -@ConditionalOnClass(Mongo.class) -@ConditionalOnMissingBean(type = "org.springframework.data.mongodb.MongoDbFactory") -@Profile({ "!cloud" }) -public class MongoConfiguration extends AbstractMongoConfiguration { - private static final Logger LOG = LoggerFactory.getLogger(MongoConfiguration.class); - - @Autowired - private MongoProperties properties; - - @Autowired(required = false) - private MongoClientOptions options; - - private Mongo mongoConnection; - - @Override - public String getDatabaseName() { - return properties.getMongoClientDatabase(); - } - - /** - * Closes mongo client when destroyed. - */ - @PreDestroy - public void close() { - if (this.mongoConnection != null) { - this.mongoConnection.close(); - } - } - - @Override - @Bean - @ConditionalOnMissingBean - // Closed by pre-destroy - @SuppressWarnings({ "squid:S2095" }) - public Mongo mongo() throws UnknownHostException { - final MongoClientURI uri = new MongoClientURI(properties.getUri(), createBuilderOutOfOptions(options)); - - if (properties.getPort() != null) { - LOG.debug("Create mongo by properties (host: {}, port: {})", uri.getHosts().get(0), properties.getPort()); - this.mongoConnection = new MongoClient( - Arrays.asList(new ServerAddress(uri.getHosts().get(0), properties.getPort())), uri.getOptions()); - } else { - LOG.debug("Create mongo by URI : {}", uri); - this.mongoConnection = new MongoClient(uri); - } - - return this.mongoConnection; - } - - /* - * Creates {@link MongoClientOptions} builder out of existing options as the - * {@link MongoClientURI} expects a builder. - * - * Based on MongoProperties#builder method. - */ - private static Builder createBuilderOutOfOptions(final MongoClientOptions options) { - final Builder builder = MongoClientOptions.builder(); - if (options != null) { - builder.alwaysUseMBeans(options.isAlwaysUseMBeans()); - builder.connectionsPerHost(options.getConnectionsPerHost()); - builder.connectTimeout(options.getConnectTimeout()); - builder.cursorFinalizerEnabled(options.isCursorFinalizerEnabled()); - builder.dbDecoderFactory(options.getDbDecoderFactory()); - builder.dbEncoderFactory(options.getDbEncoderFactory()); - builder.description(options.getDescription()); - builder.maxWaitTime(options.getMaxWaitTime()); - builder.readPreference(options.getReadPreference()); - builder.serverSelectionTimeout(options.getServerSelectionTimeout()); - builder.socketFactory(options.getSocketFactory()); - builder.socketKeepAlive(options.isSocketKeepAlive()); - builder.socketTimeout(options.getSocketTimeout()); - builder.threadsAllowedToBlockForConnectionMultiplier( - options.getThreadsAllowedToBlockForConnectionMultiplier()); - builder.writeConcern(options.getWriteConcern()); - } - return builder; - } -} diff --git a/hawkbit-artifact-repository-mongo/src/test/java/org/eclipse/hawkbit/artifact/FreePortFileWriter.java b/hawkbit-artifact-repository-mongo/src/test/java/org/eclipse/hawkbit/artifact/FreePortFileWriter.java deleted file mode 100644 index b0bcc5b6e..000000000 --- a/hawkbit-artifact-repository-mongo/src/test/java/org/eclipse/hawkbit/artifact/FreePortFileWriter.java +++ /dev/null @@ -1,78 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.artifact; - -import java.io.File; -import java.net.InetSocketAddress; -import java.net.ServerSocket; - -import org.apache.commons.io.IOUtils; - -/** - * - * Look for a free port. - */ -public class FreePortFileWriter { - - private final String filePortPath; - private final int from; - private final int to; - - /** - * @param from - * port range from (start point) - * @param to - * port range to (end point) - */ - public FreePortFileWriter(final int from, final int to, final String filePortPath) { - this.from = from; - this.to = to; - this.filePortPath = filePortPath; - } - - public int getPort() { - return findFree(); - } - - protected int findFree() { - for (int i = from; i <= to; i++) { - if (isFree(i)) { - return i; - } - } - throw new RuntimeException("No free port in range " + from + ":" + to); - } - - boolean isFree(final int port) { - ServerSocket sock = null; - try { - final File portFile = new File(filePortPath + File.separator + port + ".port"); - portFile.getParentFile().mkdirs(); - if (portFile.exists()) { - return false; - } - boolean isFree = false; - sock = new ServerSocket(); - sock.setReuseAddress(true); - sock.bind(new InetSocketAddress(port)); - if (portFile.createNewFile()) { - portFile.deleteOnExit(); - isFree = true; - } - return isFree; - // We rely on an exception thrown to determine availability or - // not availability and don't want to log the exception. - } catch (@SuppressWarnings({ "squid:S2221", "squid:S1166" }) final Exception e) { - return false; - } finally { - IOUtils.closeQuietly(sock); - } - } - -} diff --git a/hawkbit-artifact-repository-mongo/src/test/java/org/eclipse/hawkbit/artifact/MongoDBTestRule.java b/hawkbit-artifact-repository-mongo/src/test/java/org/eclipse/hawkbit/artifact/MongoDBTestRule.java deleted file mode 100644 index f5d88ceaa..000000000 --- a/hawkbit-artifact-repository-mongo/src/test/java/org/eclipse/hawkbit/artifact/MongoDBTestRule.java +++ /dev/null @@ -1,115 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.artifact; - -import java.io.IOException; -import java.net.UnknownHostException; -import java.util.UUID; - -import org.junit.rules.TestRule; -import org.junit.runner.Description; -import org.junit.runners.model.Statement; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import de.flapdoodle.embed.mongo.Command; -import de.flapdoodle.embed.mongo.MongodExecutable; -import de.flapdoodle.embed.mongo.MongodProcess; -import de.flapdoodle.embed.mongo.MongodStarter; -import de.flapdoodle.embed.mongo.config.ArtifactStoreBuilder; -import de.flapdoodle.embed.mongo.config.DownloadConfigBuilder; -import de.flapdoodle.embed.mongo.config.IMongodConfig; -import de.flapdoodle.embed.mongo.config.MongodConfigBuilder; -import de.flapdoodle.embed.mongo.config.Net; -import de.flapdoodle.embed.mongo.config.RuntimeConfigBuilder; -import de.flapdoodle.embed.mongo.distribution.Version; -import de.flapdoodle.embed.process.config.store.HttpProxyFactory; -import de.flapdoodle.embed.process.runtime.Network; - -/** - * - * - */ -public class MongoDBTestRule implements TestRule { - - private static final Logger LOG = LoggerFactory.getLogger(MongoDBTestRule.class); - private static volatile MongodExecutable mongodExecutable = null; - private static volatile MongodProcess mongod; - private final String id = UUID.randomUUID().toString(); - - @Override - public Statement apply(final Statement base, final Description description) { - return statement(base, description); - } - - private Statement statement(final Statement base, final Description description) { - return new Statement() { - @Override - public void evaluate() throws Throwable { - before(base, description); - try { - base.evaluate(); - } finally { - after(); - } - } - }; - } - - private void after() { - if (mongodExecutable != null) { - LOG.info("Stop MongoDB..."); - mongodExecutable.stop(); - mongodExecutable = null; - if (mongod != null) { - mongod.stop(); - mongod = null; - } - LOG.info("MongoDB stopped... {}", id); - } - } - - private void before(final Statement base, final Description description) throws UnknownHostException, IOException { - final Command command = Command.MongoD; - - final RuntimeConfigBuilder runtimeConfig = new RuntimeConfigBuilder().defaults(command); - - int port = -1; - if (System.getProperty("spring.data.mongodb.port") != null) { - port = Integer.parseInt(System.getProperty("spring.data.mongodb.port")); - } else { - port = new FreePortFileWriter(27017, 27100, "./target/freeports").getPort(); - System.setProperty("spring.data.mongodb.port", String.valueOf(port)); - } - - Version version = Version.V3_0_8; - if (System.getProperty("inf.mongodb.version") != null) { - version = Version.valueOf("V" + System.getProperty("inf.mongodb.version").trim().replaceAll("\\.", "_")); - } - - if (System.getProperty("http.proxyHost") != null) { - runtimeConfig.artifactStore(new ArtifactStoreBuilder().defaults(command) - .download(new DownloadConfigBuilder().defaultsForCommand(command) - .proxyFactory(new HttpProxyFactory(System.getProperty("http.proxyHost").trim(), - Integer.valueOf(System.getProperty("http.proxyPort")))))); - } - - final IMongodConfig mongodConfig = new MongodConfigBuilder().version(version) - .net(new Net("127.0.0.1", port, Network.localhostIsIPv6())).build(); - - final MongodStarter starter = MongodStarter.getInstance(runtimeConfig.build()); - mongodExecutable = starter.prepare(mongodConfig); - LOG.info("Start MongoDB..."); - mongod = mongodExecutable.start(); - - final Net net = mongod.getConfig().net(); - LOG.info("MongoDB started id {} on bind ip :{} Port:{} and version {}", id, net.getBindIp(), net.getPort(), - mongodConfig.version().toString()); - } -} diff --git a/hawkbit-artifact-repository-mongo/src/test/java/org/eclipse/hawkbit/artifact/repository/ArtifactStoreTest.java b/hawkbit-artifact-repository-mongo/src/test/java/org/eclipse/hawkbit/artifact/repository/ArtifactStoreTest.java index c5aca8e1a..fb7c141e1 100644 --- a/hawkbit-artifact-repository-mongo/src/test/java/org/eclipse/hawkbit/artifact/repository/ArtifactStoreTest.java +++ b/hawkbit-artifact-repository-mongo/src/test/java/org/eclipse/hawkbit/artifact/repository/ArtifactStoreTest.java @@ -18,10 +18,8 @@ import java.security.NoSuchAlgorithmException; import java.util.Random; import org.apache.commons.io.IOUtils; -import org.eclipse.hawkbit.artifact.MongoDBTestRule; import org.eclipse.hawkbit.artifact.TestConfiguration; import org.eclipse.hawkbit.artifact.repository.model.DbArtifact; -import org.junit.ClassRule; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -29,6 +27,7 @@ import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.data.mongodb.core.query.Criteria; import org.springframework.data.mongodb.core.query.Query; import org.springframework.data.mongodb.gridfs.GridFsOperations; +import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import com.google.common.io.BaseEncoding; @@ -42,11 +41,9 @@ import ru.yandex.qatools.allure.annotations.Stories; @Stories("Artifact Store MongoDB") @RunWith(SpringJUnit4ClassRunner.class) @SpringApplicationConfiguration(classes = { ArtifactStoreAutoConfiguration.class, TestConfiguration.class }) +@TestPropertySource(properties = { "spring.data.mongodb.port=0", "spring.mongodb.embedded.version=3.2.7" }) public class ArtifactStoreTest { - @ClassRule - public static final MongoDBTestRule mongoDBRule = new MongoDBTestRule(); - @Autowired private ArtifactStore artifactStoreUnderTest; diff --git a/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/security/SecurityManagedConfiguration.java b/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/security/SecurityManagedConfiguration.java index 66beeec5a..9a7c7df52 100644 --- a/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/security/SecurityManagedConfiguration.java +++ b/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/security/SecurityManagedConfiguration.java @@ -13,7 +13,6 @@ import static org.springframework.context.annotation.AdviceMode.ASPECTJ; import static org.springframework.core.Ordered.HIGHEST_PRECEDENCE; import java.io.IOException; -import java.net.URI; import javax.annotation.PostConstruct; import javax.servlet.Filter; @@ -22,7 +21,6 @@ import javax.servlet.FilterConfig; import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; -import javax.validation.constraints.NotNull; import org.eclipse.hawkbit.ExcludePathAwareShallowETagFilter; import org.eclipse.hawkbit.cache.CacheConstants; @@ -69,7 +67,6 @@ import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.builders.WebSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; -import org.springframework.security.config.annotation.web.servlet.configuration.EnableWebMvcSecurity; import org.springframework.security.config.http.SessionCreationPolicy; import org.springframework.security.core.Authentication; import org.springframework.security.core.authority.SimpleGrantedAuthority; @@ -80,9 +77,6 @@ import org.springframework.security.web.authentication.LoginUrlAuthenticationEnt import org.springframework.security.web.authentication.preauth.RequestHeaderAuthenticationFilter; import org.springframework.security.web.authentication.www.BasicAuthenticationEntryPoint; import org.springframework.security.web.authentication.www.BasicAuthenticationFilter; -import org.springframework.security.web.header.writers.frameoptions.StaticAllowFromStrategy; -import org.springframework.security.web.header.writers.frameoptions.XFrameOptionsHeaderWriter; -import org.springframework.security.web.header.writers.frameoptions.XFrameOptionsHeaderWriter.XFrameOptionsMode; import org.springframework.security.web.session.HttpSessionEventPublisher; import org.springframework.security.web.session.SessionManagementFilter; import org.vaadin.spring.security.VaadinSecurityContext; @@ -99,7 +93,6 @@ import org.vaadin.spring.security.web.authentication.VaadinUrlAuthenticationSucc @Configuration @EnableWebSecurity @EnableGlobalMethodSecurity(prePostEnabled = true, mode = ASPECTJ, proxyTargetClass = true, securedEnabled = true) -@EnableWebMvcSecurity @Order(value = HIGHEST_PRECEDENCE) public class SecurityManagedConfiguration { @@ -191,9 +184,7 @@ public class SecurityManagedConfiguration { controllerAnonymousDownloadFilter.setCheckForPrincipalChanges(true); controllerAnonymousDownloadFilter.setAuthenticationDetailsSource(authenticationDetailsSource); - HttpSecurity httpSec = http.csrf().disable().headers() - .addHeaderWriter(new XFrameOptionsHeaderWriter(XFrameOptionsMode.DENY)).contentTypeOptions() - .xssProtection().httpStrictTransportSecurity().and(); + HttpSecurity httpSec = http.csrf().disable(); if (springSecurityProperties.isRequireSsl()) { httpSec = httpSec.requiresChannel().anyRequest().requiresSecure().and(); @@ -342,20 +333,12 @@ public class SecurityManagedConfiguration { @Order(400) @EnableVaadinSecurity public static class UISecurityConfigurationAdapter extends WebSecurityConfigurerAdapter { - - private static final String XFRAME_OPTION_DENY = "DENY"; - private static final String XFRAME_OPTION_SAMEORIGIN = "SAMEORIGIN"; - private static final String XFAME_OPTION_ALLOW_FROM = "ALLOW-FROM"; - @Autowired private VaadinSecurityContext vaadinSecurityContext; @Autowired private org.springframework.boot.autoconfigure.security.SecurityProperties springSecurityProperties; - @Autowired - private HawkbitSecurityProperties securityProperties; - /** * post construct for setting the authentication success handler for the * vaadin security context. @@ -409,18 +392,6 @@ public class SecurityManagedConfiguration { @Override protected void configure(final HttpSecurity http) throws Exception { - // configuration xframe-option - final String confXframeOption = securityProperties.getXframe().getOption(); - final String confAllowFromUri = securityProperties.getXframe().getAllowfrom(); - - if (XFAME_OPTION_ALLOW_FROM.equals(confXframeOption) && confAllowFromUri.isEmpty()) { - // if allow-from option is specified but no allowFromUri throw - // exception - throw new IllegalStateException("hawkbit.server.security.xframe.option has been specified as ALLOW-FROM" - + " but no hawkbit.server.security.xframe.allowfrom has been set, " - + "please ensure to set allow from URIs"); - } - // workaround regex: we need to exclude the URL /UI/HEARTBEAT here // because we bound the vaadin application to /UI and not to root, // described in vaadin-forum: @@ -437,12 +408,7 @@ public class SecurityManagedConfiguration { "\"******************\\n** Requires HTTPS Security has been disabled for UI, should only be used for developing purposes **\\n******************\""); } - // for UI integrator we allow frame integration on same origin - httpSec.headers() - .addHeaderWriter(confXframeOption.equals(XFAME_OPTION_ALLOW_FROM) - ? new XFrameOptionsHeaderWriter(new StaticAllowFromStrategy(new URI(confAllowFromUri))) - : new XFrameOptionsHeaderWriter(xframeOptionFromStr(confXframeOption))) - .contentTypeOptions().xssProtection().httpStrictTransportSecurity().and() + httpSec // UI .authorizeRequests().antMatchers("/UI/login/**").permitAll().antMatchers("/UI/UIDL/**").permitAll() .anyRequest().authenticated().and() @@ -451,29 +417,6 @@ public class SecurityManagedConfiguration { .and().logout().logoutUrl("/UI/logout").logoutSuccessUrl("/UI/login/#/"); } - /** - * Converts a given string into the {@link XFrameOptionsMode} enum. Only - * {@link XFrameOptionsMode#DENY} and - * {@link XFrameOptionsMode#SAMEORIGIN} any other string will be - * converted to the default {@link XFrameOptionsMode#SAMEORIGIN}. - * - * @param xframeOption - * the string of the xframe option - * @return an {@link XFrameOptionsMode} by the given string, in case - * string does not match an option then - * {@link XFrameOptionsMode#SAMEORIGIN} is returned - */ - private static XFrameOptionsMode xframeOptionFromStr(@NotNull final String xframeOption) { - switch (xframeOption) { - case XFRAME_OPTION_DENY: - return XFrameOptionsMode.DENY; - case XFRAME_OPTION_SAMEORIGIN: - // fall through to default because the same - default: - return XFrameOptionsMode.SAMEORIGIN; - } - } - @Override public void configure(final WebSecurity webSecurity) throws Exception { webSecurity.ignoring().antMatchers("/documentation/**", "/VAADIN/**", "/*.*", "/v2/api-docs/**", diff --git a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactDownloadTest.java b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactDownloadTest.java index 81be97b7c..d8931ab41 100644 --- a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactDownloadTest.java +++ b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactDownloadTest.java @@ -21,12 +21,15 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.nio.charset.StandardCharsets; +import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Arrays; +import java.util.Date; import java.util.List; +import java.util.TimeZone; import org.apache.commons.lang3.RandomUtils; -import org.eclipse.hawkbit.repository.eventbus.event.DownloadProgressEvent; +import org.eclipse.hawkbit.eventbus.event.DownloadProgressEvent; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.Status; import org.eclipse.hawkbit.repository.model.Artifact; @@ -35,6 +38,7 @@ import org.eclipse.hawkbit.repository.model.LocalArtifact; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.test.util.WithUser; import org.eclipse.hawkbit.rest.AbstractRestIntegrationTestWithMongoDB; +import org.junit.Before; import org.junit.Test; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -59,15 +63,18 @@ import ru.yandex.qatools.allure.annotations.Stories; @Stories("Artifact Download Resource") public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMongoDB { - private static final int ARTIFACT_SIZE = 5 * 1024 * 1024; - public DdiArtifactDownloadTest() { LOG = LoggerFactory.getLogger(DdiArtifactDownloadTest.class); } private volatile int downLoadProgress = 0; - private volatile long shippedBytes = 0; - private volatile long shippedBytesTotal = 0; + + private final SimpleDateFormat dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz"); + + @Before + public void setup() { + dateFormat.setTimeZone(TimeZone.getTimeZone("GMT")); + } @Autowired private EventBus eventBus; @@ -240,8 +247,6 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong @Description("Tests valid downloads through the artifact resource by identifying the artifact not by ID but file name.") public void downloadArtifactThroughFileName() throws Exception { downLoadProgress = 1; - shippedBytes = 0; - shippedBytesTotal = 0; eventBus.register(this); assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(0); @@ -255,7 +260,7 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong final DistributionSet ds = testdataFactory.createDistributionSet(""); // create artifact - final byte random[] = RandomUtils.nextBytes(ARTIFACT_SIZE); + final byte random[] = RandomUtils.nextBytes(5 * 1024 * 1024); final LocalArtifact artifact = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), ds.findFirstModuleByType(osType).getId(), "file1", false); @@ -273,7 +278,7 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong ds.findFirstModuleByType(osType).getId(), artifact.getFilename())) .andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_OCTET_STREAM)) .andExpect(header().string("Accept-Ranges", "bytes")) - .andExpect(header().longValue("Last-Modified", artifact.getCreatedAt())) + .andExpect(header().string("Last-Modified", dateFormat.format(new Date(artifact.getCreatedAt())))) .andExpect(header().string("Content-Disposition", "attachment;filename=" + artifact.getFilename())) .andReturn(); @@ -282,7 +287,6 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong // download complete assertThat(downLoadProgress).isEqualTo(10); - assertThat(shippedBytes).isEqualTo(shippedBytesTotal).isEqualTo(ARTIFACT_SIZE); } @Test @@ -320,8 +324,6 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong + "anonymous as authorization is notpossible, e.g. chekc if the controller has the artifact assigned.") public void downloadArtifactByNameFailsIfNotAuthenticated() throws Exception { downLoadProgress = 1; - shippedBytes = 0; - shippedBytesTotal = 0; eventBus.register(this); assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(0); @@ -329,24 +331,21 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong // create target Target target = entityFactory.generateTarget("4712"); target = targetManagement.createTarget(target); - final List targets = new ArrayList<>(); + final List targets = new ArrayList(); targets.add(target); // create ds final DistributionSet ds = testdataFactory.createDistributionSet(""); // create artifact - final byte random[] = RandomUtils.nextBytes(ARTIFACT_SIZE); - artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), + final byte random[] = RandomUtils.nextBytes(5 * 1024); + final Artifact artifact = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), ds.findFirstModuleByType(osType).getId(), "file1.tar.bz2", false); // download fails as artifact is not yet assigned to target deploymentManagement.assignDistributionSet(ds, targets); mvc.perform(get("/controller/artifacts/v1/filename/{filename}", "file1.tar.bz2")) .andExpect(status().isNotFound()); - - assertThat(downLoadProgress).isEqualTo(1); - assertThat(shippedBytes).isEqualTo(shippedBytesTotal).isEqualTo(0L); } @Test @@ -354,8 +353,6 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong @Description("Ensures that an authenticated and named controller is permitted to download.") public void downloadArtifactByNameByNamedController() throws Exception { downLoadProgress = 1; - shippedBytes = 0; - shippedBytesTotal = 0; eventBus.register(this); assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(0); @@ -370,7 +367,7 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong final DistributionSet ds = testdataFactory.createDistributionSet(""); // create artifact - final byte random[] = RandomUtils.nextBytes(ARTIFACT_SIZE); + final byte random[] = RandomUtils.nextBytes(5 * 1024 * 1024); final Artifact artifact = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), ds.findFirstModuleByType(osType).getId(), "file1", false); @@ -386,7 +383,7 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong .andExpect(status().isOk()).andExpect(header().string("ETag", artifact.getSha1Hash())) .andExpect(content().contentType(MediaType.APPLICATION_OCTET_STREAM)) .andExpect(header().string("Accept-Ranges", "bytes")) - .andExpect(header().longValue("Last-Modified", artifact.getCreatedAt())) + .andExpect(header().string("Last-Modified", dateFormat.format(new Date(artifact.getCreatedAt())))) .andExpect(header().string("Content-Disposition", "attachment;filename=file1")).andReturn(); assertTrue("The same file that was uploaded is expected when downloaded", @@ -403,7 +400,6 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong // download complete assertThat(downLoadProgress).isEqualTo(10); - assertThat(shippedBytes).isEqualTo(shippedBytesTotal).isEqualTo(ARTIFACT_SIZE); } @Test @@ -444,7 +440,7 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong .andExpect(status().isPartialContent()).andExpect(header().string("ETag", artifact.getSha1Hash())) .andExpect(content().contentType(MediaType.APPLICATION_OCTET_STREAM)) .andExpect(header().string("Accept-Ranges", "bytes")) - .andExpect(header().longValue("Last-Modified", artifact.getCreatedAt())) + .andExpect(header().string("Last-Modified", dateFormat.format(new Date(artifact.getCreatedAt())))) .andExpect(header().longValue("Content-Length", range)) .andExpect(header().string("Content-Range", "bytes " + rangeString + "/" + resultLength)) .andExpect(header().string("Content-Disposition", "attachment;filename=file1")).andReturn(); @@ -461,7 +457,7 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong .andExpect(status().isPartialContent()).andExpect(header().string("ETag", artifact.getSha1Hash())) .andExpect(content().contentType(MediaType.APPLICATION_OCTET_STREAM)) .andExpect(header().string("Accept-Ranges", "bytes")) - .andExpect(header().longValue("Last-Modified", artifact.getCreatedAt())) + .andExpect(header().string("Last-Modified", dateFormat.format(new Date(artifact.getCreatedAt())))) .andExpect(header().longValue("Content-Length", 1000)) .andExpect(header().string("Content-Range", "bytes " + (resultLength - 1000) + "-" + (resultLength - 1) + "/" + resultLength)) @@ -477,7 +473,7 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong .andExpect(status().isPartialContent()).andExpect(header().string("ETag", artifact.getSha1Hash())) .andExpect(content().contentType(MediaType.APPLICATION_OCTET_STREAM)) .andExpect(header().string("Accept-Ranges", "bytes")) - .andExpect(header().longValue("Last-Modified", artifact.getCreatedAt())) + .andExpect(header().string("Last-Modified", dateFormat.format(new Date(artifact.getCreatedAt())))) .andExpect(header().longValue("Content-Length", resultLength - 1000)) .andExpect(header().string("Content-Range", "bytes " + 1000 + "-" + (resultLength - 1) + "/" + resultLength)) @@ -493,7 +489,7 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong .andExpect(status().isPartialContent()).andExpect(header().string("ETag", artifact.getSha1Hash())) .andExpect(content().contentType("multipart/byteranges; boundary=THIS_STRING_SEPARATES_MULTIPART")) .andExpect(header().string("Accept-Ranges", "bytes")) - .andExpect(header().longValue("Last-Modified", artifact.getCreatedAt())) + .andExpect(header().string("Last-Modified", dateFormat.format(new Date(artifact.getCreatedAt())))) .andExpect(header().string("Content-Disposition", "attachment;filename=file1")).andReturn(); outputStream.reset(); @@ -565,8 +561,5 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong @Subscribe public void listen(final DownloadProgressEvent event) { downLoadProgress++; - shippedBytes += event.getShippedBytesSinceLast(); - shippedBytesTotal = event.getShippedBytesOverall(); - } } diff --git a/hawkbit-ddi-resource/src/test/resources/logback.xml b/hawkbit-ddi-resource/src/test/resources/logback-spring.xml similarity index 79% rename from hawkbit-ddi-resource/src/test/resources/logback.xml rename to hawkbit-ddi-resource/src/test/resources/logback-spring.xml index 447712338..c5d0969e1 100644 --- a/hawkbit-ddi-resource/src/test/resources/logback.xml +++ b/hawkbit-ddi-resource/src/test/resources/logback-spring.xml @@ -12,10 +12,10 @@ - + - + \ No newline at end of file diff --git a/hawkbit-dmf-amqp/src/test/resources/logback.xml b/hawkbit-dmf-amqp/src/test/resources/logback-spring.xml similarity index 97% rename from hawkbit-dmf-amqp/src/test/resources/logback.xml rename to hawkbit-dmf-amqp/src/test/resources/logback-spring.xml index 30060d1c6..6dd6c94e0 100644 --- a/hawkbit-dmf-amqp/src/test/resources/logback.xml +++ b/hawkbit-dmf-amqp/src/test/resources/logback-spring.xml @@ -29,7 +29,7 @@ - + \ No newline at end of file diff --git a/hawkbit-http-security/src/main/java/org/eclipse/hawkbit/security/AbstractHttpControllerAuthenticationFilter.java b/hawkbit-http-security/src/main/java/org/eclipse/hawkbit/security/AbstractHttpControllerAuthenticationFilter.java index 0a4ad0b72..9aa5c72f9 100644 --- a/hawkbit-http-security/src/main/java/org/eclipse/hawkbit/security/AbstractHttpControllerAuthenticationFilter.java +++ b/hawkbit-http-security/src/main/java/org/eclipse/hawkbit/security/AbstractHttpControllerAuthenticationFilter.java @@ -115,7 +115,7 @@ public abstract class AbstractHttpControllerAuthenticationFilter extends Abstrac @Override protected void successfulAuthentication(final HttpServletRequest request, final HttpServletResponse response, - final Authentication authResult) { + final Authentication authResult) throws IOException, ServletException { final Collection authorities = new ArrayList<>(); authorities.addAll(authResult.getAuthorities()); authorities.addAll(abstractControllerAuthenticationFilter.getSuccessfulAuthenticationAuthorities()); diff --git a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/SMRessourceMisingMongoDbConnectionTest.java b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/SMRessourceMisingMongoDbConnectionTest.java index de0411006..737bf50d5 100644 --- a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/SMRessourceMisingMongoDbConnectionTest.java +++ b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/SMRessourceMisingMongoDbConnectionTest.java @@ -15,10 +15,10 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. import org.apache.commons.lang3.RandomStringUtils; import org.eclipse.hawkbit.exception.SpServerError; import org.eclipse.hawkbit.repository.model.SoftwareModule; -import org.eclipse.hawkbit.rest.AbstractRestIntegrationTest; +import org.eclipse.hawkbit.rest.AbstractRestIntegrationTestWithMongoDB; import org.eclipse.hawkbit.rest.json.model.ExceptionInfo; import org.eclipse.hawkbit.rest.util.MockMvcResultPrinter; -import org.junit.BeforeClass; +import org.junit.After; import org.junit.Test; import org.springframework.mock.web.MockMultipartFile; import org.springframework.test.web.servlet.MvcResult; @@ -34,23 +34,17 @@ import ru.yandex.qatools.allure.annotations.Stories; */ @Features("Component Tests - Management API") @Stories("Download Resource") -public class SMRessourceMisingMongoDbConnectionTest extends AbstractRestIntegrationTest { - - @BeforeClass - public static void initialize() { - // set property to mongoPort which does not start any mongoDB of - // parallel test execution - System.setProperty("spring.data.mongodb.port", "1020"); - } +public class SMRessourceMisingMongoDbConnectionTest extends AbstractRestIntegrationTestWithMongoDB { @Test @Description("Ensures that the correct error code is returned in case MongoDB unavailable.") public void missingMongoDbConnectionResultsInErrorAtUpload() throws Exception { + mongodExecutable.stop(); assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(0); assertThat(artifactManagement.countLocalArtifactsAll()).isEqualTo(0); - SoftwareModule sm = entityFactory.generateSoftwareModule( - softwareManagement.findSoftwareModuleTypeByKey("os"), "name 1", "version 1", null, null); + SoftwareModule sm = entityFactory.generateSoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), + "name 1", "version 1", null, null); sm = softwareManagement.createSoftwareModule(sm); assertThat(artifactManagement.countLocalArtifactsAll()).isEqualTo(0); @@ -74,4 +68,9 @@ public class SMRessourceMisingMongoDbConnectionTest extends AbstractRestIntegrat } + @After + public void cleanCurrentCollection() { + // not needed, mongodb is stopped already + } + } diff --git a/hawkbit-mgmt-resource/src/test/resources/logback.xml b/hawkbit-mgmt-resource/src/test/resources/logback-spring.xml similarity index 97% rename from hawkbit-mgmt-resource/src/test/resources/logback.xml rename to hawkbit-mgmt-resource/src/test/resources/logback-spring.xml index 30060d1c6..6dd6c94e0 100644 --- a/hawkbit-mgmt-resource/src/test/resources/logback.xml +++ b/hawkbit-mgmt-resource/src/test/resources/logback-spring.xml @@ -29,7 +29,7 @@ - + \ No newline at end of file diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ArtifactManagementFailedMongoDBTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ArtifactManagementFailedMongoDBTest.java new file mode 100644 index 000000000..98af08494 --- /dev/null +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ArtifactManagementFailedMongoDBTest.java @@ -0,0 +1,74 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.jpa; + +import static org.fest.assertions.api.Assertions.assertThat; +import static org.junit.Assert.fail; + +import java.io.IOException; +import java.net.UnknownHostException; + +import org.eclipse.hawkbit.repository.exception.ArtifactDeleteFailedException; +import org.eclipse.hawkbit.repository.exception.ArtifactUploadFailedException; +import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule; +import org.eclipse.hawkbit.repository.model.Artifact; +import org.junit.After; +import org.junit.Test; + +import ru.yandex.qatools.allure.annotations.Description; +import ru.yandex.qatools.allure.annotations.Features; +import ru.yandex.qatools.allure.annotations.Stories; + +@Features("Component Tests - Repository") +@Stories("Artifact Management") +public class ArtifactManagementFailedMongoDBTest extends AbstractJpaIntegrationTestWithMongoDB { + + @Test + @Description("Trys and fails to delete or create local artifact with a down mongodb and checks if expected ArtifactDeleteFailedException is thrown.") + public void deleteArtifactsWithNoMongoDb() throws UnknownHostException, IOException { + // ensure baseline + assertThat(artifactRepository.findAll()).isEmpty(); + + // prepare test + JpaSoftwareModule sm = new JpaSoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), "name 1", + "version 1", null, null); + sm = softwareModuleRepository.save(sm); + + final Artifact result = artifactManagement.createLocalArtifact(new RandomGeneratedInputStream(5 * 1024), + sm.getId(), "file1", false); + + assertThat(artifactRepository.findAll()).hasSize(1); + + mongodExecutable.stop(); + try { + artifactManagement.deleteLocalArtifact(result.getId()); + fail("deletion should have failed"); + } catch (final ArtifactDeleteFailedException e) { + + } + + try { + artifactManagement.createLocalArtifact(new RandomGeneratedInputStream(5 * 1024), sm.getId(), "file2", + false); + fail("Should not have worked with MongoDb down."); + } catch (final ArtifactUploadFailedException e) { + + } + + assertThat(artifactRepository.findAll()).hasSize(1); + + } + + @Override + @After + public void cleanCurrentCollection() { + // no need to clean, is stopped already + } + +} diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ArtifactManagementNoMongoDbTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ArtifactManagementNoMongoDbTest.java deleted file mode 100644 index 42b759b74..000000000 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ArtifactManagementNoMongoDbTest.java +++ /dev/null @@ -1,58 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.repository.jpa; - -import static org.junit.Assert.fail; - -import java.io.ByteArrayInputStream; -import java.io.IOException; - -import org.apache.commons.lang3.RandomStringUtils; -import org.eclipse.hawkbit.repository.exception.ArtifactUploadFailedException; -import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule; -import org.junit.BeforeClass; -import org.junit.Test; - -import ru.yandex.qatools.allure.annotations.Description; -import ru.yandex.qatools.allure.annotations.Features; -import ru.yandex.qatools.allure.annotations.Stories; - -/** - * Addition tests next to {@link ArtifactManagementTest} with no running MongoDB - * - */ -@Features("Component Tests - Repository") -@Stories("Artifact Management") -public class ArtifactManagementNoMongoDbTest extends AbstractJpaIntegrationTest { - - @BeforeClass - public static void initialize() { - // set property to mongoPort which does not start any mongoDB of - // parallel test execution - System.setProperty("spring.data.mongodb.port", "1020"); - } - - @Test - @Description("Checks if the expected ArtifactUploadFailedException is thrown in case of MongoDB down") - public void createLocalArtifactWithMongoDbDown() throws IOException { - JpaSoftwareModule sm = new JpaSoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), "name 1", - "version 1", null, null); - sm = softwareModuleRepository.save(sm); - - final byte random[] = RandomStringUtils.random(5 * 1024).getBytes(); - - try { - artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), sm.getId(), "file1", false); - fail("Should not have worked with MongoDb down."); - } catch (final ArtifactUploadFailedException e) { - - } - } - -} diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ArtifactManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ArtifactManagementTest.java index 293dcdf91..ac12ff4f9 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ArtifactManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ArtifactManagementTest.java @@ -15,14 +15,12 @@ import static org.junit.Assert.fail; import java.io.ByteArrayInputStream; import java.io.IOException; -import java.net.UnknownHostException; import java.security.NoSuchAlgorithmException; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.RandomStringUtils; import org.eclipse.hawkbit.im.authentication.SpPermission; import org.eclipse.hawkbit.repository.ArtifactManagement; -import org.eclipse.hawkbit.repository.exception.ArtifactDeleteFailedException; import org.eclipse.hawkbit.repository.exception.InsufficientPermissionException; import org.eclipse.hawkbit.repository.jpa.model.JpaExternalArtifact; import org.eclipse.hawkbit.repository.jpa.model.JpaExternalArtifactProvider; @@ -241,36 +239,6 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTestWithMongoD assertThat(artifactRepository.findAll()).hasSize(0); } - @Test - @Description("Trys and fails to delete local artifact with a down mongodb and checks if expected ArtifactDeleteFailedException is thrown.") - public void deleteArtifactsWithNoMongoDb() throws UnknownHostException, IOException { - // ensure baseline - assertThat(artifactRepository.findAll()).isEmpty(); - - // prepare test - JpaSoftwareModule sm = new JpaSoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), "name 1", - "version 1", null, null); - sm = softwareModuleRepository.save(sm); - - final Artifact result = artifactManagement.createLocalArtifact(new RandomGeneratedInputStream(5 * 1024), - sm.getId(), "file1", false); - - assertThat(artifactRepository.findAll()).hasSize(1); - - internalShutDownMongo(); - try { - artifactManagement.deleteLocalArtifact(result.getId()); - fail("deletion should have failed"); - } catch (final ArtifactDeleteFailedException e) { - - } - setupMongo(); - - assertThat(artifactRepository.findAll()).hasSize(1); - assertThat(artifactManagement.findArtifact(result.getId())).isEqualTo(result); - - } - @Test @Description("Test the deletion of an artifact metadata where the binary is still linked to another " + "metadata element. The expected result is that the metadata is deleted but the binary kept.") diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/resources/logback-spring.xml b/hawkbit-repository/hawkbit-repository-jpa/src/test/resources/logback-spring.xml new file mode 100644 index 000000000..4a7755609 --- /dev/null +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/resources/logback-spring.xml @@ -0,0 +1,19 @@ + + + + + + + + + + \ No newline at end of file diff --git a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/AbstractIntegrationTest.java b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/AbstractIntegrationTest.java index fe8e40da0..127de332d 100644 --- a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/AbstractIntegrationTest.java +++ b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/AbstractIntegrationTest.java @@ -51,6 +51,7 @@ import org.springframework.data.domain.Pageable; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext.ClassMode; import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.test.web.servlet.MockMvc; @@ -68,6 +69,7 @@ import org.springframework.web.context.WebApplicationContext; // refreshed we e.g. get two instances of CacheManager which leads to very // strange test failures. @DirtiesContext(classMode = ClassMode.AFTER_CLASS) +@TestPropertySource(properties = { "spring.data.mongodb.port=0", "spring.mongodb.embedded.version=3.2.7" }) public abstract class AbstractIntegrationTest implements EnvironmentAware { protected static Logger LOG = null; diff --git a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/AbstractIntegrationTestWithMongoDB.java b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/AbstractIntegrationTestWithMongoDB.java index bb54f550c..589cac381 100644 --- a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/AbstractIntegrationTestWithMongoDB.java +++ b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/AbstractIntegrationTestWithMongoDB.java @@ -8,103 +8,27 @@ */ package org.eclipse.hawkbit.repository.test.util; -import java.io.IOException; -import java.net.UnknownHostException; -import java.util.concurrent.atomic.AtomicInteger; - import org.junit.After; -import org.junit.AfterClass; -import org.junit.BeforeClass; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.mongodb.core.query.Query; import org.springframework.data.mongodb.gridfs.GridFsOperations; -import de.flapdoodle.embed.mongo.Command; import de.flapdoodle.embed.mongo.MongodExecutable; -import de.flapdoodle.embed.mongo.MongodStarter; -import de.flapdoodle.embed.mongo.config.ArtifactStoreBuilder; -import de.flapdoodle.embed.mongo.config.DownloadConfigBuilder; -import de.flapdoodle.embed.mongo.config.IMongodConfig; -import de.flapdoodle.embed.mongo.config.MongodConfigBuilder; -import de.flapdoodle.embed.mongo.config.Net; -import de.flapdoodle.embed.mongo.config.RuntimeConfigBuilder; -import de.flapdoodle.embed.mongo.distribution.Version; -import de.flapdoodle.embed.process.config.store.HttpProxyFactory; -import de.flapdoodle.embed.process.runtime.Network; /** - * Test class that contains MonfoDb start and stop for the test - * - * - * - * + * Test class that contains embedded MongoDB for the test. */ public abstract class AbstractIntegrationTestWithMongoDB extends AbstractIntegrationTest { - protected static volatile MongodExecutable mongodExecutable = null; - private static final AtomicInteger mongoLease = new AtomicInteger(0); - private static volatile Integer port; - @Autowired protected GridFsOperations operations; - @BeforeClass - public static void setupMongo() throws UnknownHostException, IOException { - mongoLease.incrementAndGet(); - if (mongodExecutable == null) { - final Command command = Command.MongoD; - - final RuntimeConfigBuilder runtimeConfig = new RuntimeConfigBuilder().defaults(command); - - if (port == null) { - port = new FreePortFileWriter(28017, 28090, "./target/freeports").getPort(); - System.setProperty("spring.data.mongodb.port", String.valueOf(port)); - } - - Version version = Version.V3_0_8; - if (System.getProperty("inf.mongodb.version") != null) { - version = Version - .valueOf("V" + System.getProperty("inf.mongodb.version").trim().replaceAll("\\.", "_")); - } - - if (System.getProperty("http.proxyHost") != null) { - runtimeConfig - .artifactStore( - new ArtifactStoreBuilder().defaults(command) - .download(new DownloadConfigBuilder().defaultsForCommand(command) - .proxyFactory(new HttpProxyFactory( - System.getProperty("http.proxyHost").trim(), Integer - .valueOf(System.getProperty("http.proxyPort")))))); - } - - final IMongodConfig mongodConfig = new MongodConfigBuilder().version(version) - .net(new Net("127.0.0.1", port, Network.localhostIsIPv6())).build(); - - final MongodStarter starter = MongodStarter.getInstance(runtimeConfig.build()); - mongodExecutable = starter.prepare(mongodConfig); - mongodExecutable.start(); - } - - } + @Autowired + protected MongodExecutable mongodExecutable; @After public void cleanCurrentCollection() { operations.delete(new Query()); } - public static void internalShutDownMongo() { - if (mongodExecutable != null && mongoLease.decrementAndGet() <= 0) { - mongodExecutable.stop(); - mongodExecutable = null; - } - } - - @AfterClass - public static void shutdownMongo() throws UnknownHostException, IOException { - if (mongodExecutable != null && mongoLease.decrementAndGet() <= 0) { - mongodExecutable.stop(); - mongodExecutable = null; - } - port = null; - } } diff --git a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/FreePortFileWriter.java b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/FreePortFileWriter.java deleted file mode 100644 index 635cc9d6e..000000000 --- a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/FreePortFileWriter.java +++ /dev/null @@ -1,73 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.repository.test.util; - -import java.io.File; -import java.net.InetSocketAddress; -import java.net.ServerSocket; - -/** - * - * Look for a free port. - */ -public class FreePortFileWriter { - - private final String filePortPath; - private final int from; - private final int to; - - /** - * @param from - * port range from (start point) - * @param to - * port range to (end point) - */ - public FreePortFileWriter(final int from, final int to, final String filePortPath) { - this.from = from; - this.to = to; - this.filePortPath = filePortPath; - } - - public int getPort() { - return findFree(); - } - - protected int findFree() { - for (int i = from; i <= to; i++) { - if (isFree(i)) { - return i; - } - } - throw new RuntimeException("No free port in range " + from + ":" + to); - } - - boolean isFree(final int port) { - try { - final File portFile = new File(filePortPath + File.separator + port + ".port"); - portFile.getParentFile().mkdirs(); - if (portFile.exists()) { - return false; - } - boolean isFree = false; - final ServerSocket sock = new ServerSocket(); - sock.setReuseAddress(true); - sock.bind(new InetSocketAddress(port)); - if (portFile.createNewFile()) { - portFile.deleteOnExit(); - isFree = true; - } - sock.close(); - return isFree; - // We rely on an exception thrown to determine availability or - // not availability and don't want to log the exception. - } catch (@SuppressWarnings({ "squid:S2221", "squid:S1166" }) final Exception e) { - return false; - } - } -} diff --git a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/TestConfiguration.java b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/TestConfiguration.java index 3a7a2f73d..dbdc0db82 100644 --- a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/TestConfiguration.java +++ b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/TestConfiguration.java @@ -45,11 +45,10 @@ import com.mongodb.MongoClientOptions; * */ @Configuration -@EnableGlobalMethodSecurity(prePostEnabled = true, mode = AdviceMode.ASPECTJ, proxyTargetClass = true, securedEnabled = true) +@EnableGlobalMethodSecurity(prePostEnabled = true, mode = AdviceMode.PROXY, proxyTargetClass = false, securedEnabled = true) @EnableConfigurationProperties({ HawkbitServerProperties.class, DdiSecurityProperties.class }) @Profile("test") public class TestConfiguration implements AsyncConfigurer { - @Bean public TestRepositoryManagement testRepositoryManagement() { return new JpaTestRepositoryManagement(); diff --git a/hawkbit-security-core/src/main/java/org/eclipse/hawkbit/im/authentication/SpPermission.java b/hawkbit-security-core/src/main/java/org/eclipse/hawkbit/im/authentication/SpPermission.java index 866ee16bc..6a68aee5b 100644 --- a/hawkbit-security-core/src/main/java/org/eclipse/hawkbit/im/authentication/SpPermission.java +++ b/hawkbit-security-core/src/main/java/org/eclipse/hawkbit/im/authentication/SpPermission.java @@ -185,22 +185,18 @@ public final class SpPermission { field.setAccessible(true); try { final String role = (String) field.get(null); - addIfNotExcluded(exclusionRoles, allPermissions, role); + if (!(exclusionRoles.contains(role))) { + allPermissions.add(role); + } } catch (final IllegalAccessException e) { LOGGER.error(e.getMessage(), e); } + } } return allPermissions; } - private static void addIfNotExcluded(final Collection exclusionRoles, final List allPermissions, - final String role) { - if (!(exclusionRoles.contains(role))) { - allPermissions.add(role); - } - } - /** * Contains all the spring security evaluation expressions for the * {@link PreAuthorize} annotation for method security. @@ -228,10 +224,8 @@ public final class SpPermission { /* * Spring security eval expressions. */ - private static final String BRACKET_OPEN = "("; - private static final String BRACKET_CLOSE = ")"; - private static final String HAS_AUTH_PREFIX = "hasAuthority" + BRACKET_OPEN + "'"; - private static final String HAS_AUTH_SUFFIX = "'" + BRACKET_CLOSE; + private static final String HAS_AUTH_PREFIX = "hasAuthority('"; + private static final String HAS_AUTH_SUFFIX = "')"; private static final String HAS_AUTH_AND = " and "; /** @@ -263,6 +257,99 @@ public final class SpPermission { */ public static final String HAS_AUTH_OR = " or "; + /** + * Spring security eval hasAuthority expression to check if spring + * context contains {@link SpPermission#UPDATE_TARGET}. + */ + public static final String HAS_AUTH_UPDATE_TARGET = HAS_AUTH_PREFIX + UPDATE_TARGET + HAS_AUTH_SUFFIX; + + /** + * Spring security eval hasAuthority expression to check if spring + * context contains {@link SpPermission#SYSTEM_ADMIN}. + */ + public static final String HAS_AUTH_SYSTEM_ADMIN = HAS_AUTH_PREFIX + SYSTEM_ADMIN + HAS_AUTH_SUFFIX; + + /** + * Spring security eval hasAuthority expression to check if spring + * context contains {@link SpPermission#READ_TARGET}. + */ + public static final String HAS_AUTH_READ_TARGET = HAS_AUTH_PREFIX + READ_TARGET + HAS_AUTH_SUFFIX; + + /** + * Spring security eval hasAuthority expression to check if spring + * context contains {@link SpPermission#CREATE_TARGET}. + */ + public static final String HAS_AUTH_CREATE_TARGET = HAS_AUTH_PREFIX + CREATE_TARGET + HAS_AUTH_SUFFIX; + + /** + * Spring security eval hasAuthority expression to check if spring + * context contains {@link SpPermission#DELETE_TARGET}. + */ + public static final String HAS_AUTH_DELETE_TARGET = HAS_AUTH_PREFIX + DELETE_TARGET + HAS_AUTH_SUFFIX; + + /** + * Spring security eval hasAuthority expression to check if spring + * context contains {@link SpPermission#READ_REPOSITORY} and + * {@link SpPermission#UPDATE_TARGET}. + */ + public static final String HAS_AUTH_READ_REPOSITORY_AND_UPDATE_TARGET = HAS_AUTH_PREFIX + READ_REPOSITORY + + HAS_AUTH_SUFFIX + HAS_AUTH_AND + HAS_AUTH_PREFIX + UPDATE_TARGET + HAS_AUTH_SUFFIX; + + /** + * Spring security eval hasAuthority expression to check if spring + * context contains {@link SpPermission#CREATE_REPOSITORY}. + */ + public static final String HAS_AUTH_CREATE_REPOSITORY = HAS_AUTH_PREFIX + CREATE_REPOSITORY + HAS_AUTH_SUFFIX; + + /** + * Spring security eval hasAuthority expression to check if spring + * context contains {@link SpPermission#DELETE_REPOSITORY}. + */ + public static final String HAS_AUTH_DELETE_REPOSITORY = HAS_AUTH_PREFIX + DELETE_REPOSITORY + HAS_AUTH_SUFFIX; + + /** + * Spring security eval hasAuthority expression to check if spring + * context contains {@link SpPermission#READ_REPOSITORY}. + */ + public static final String HAS_AUTH_READ_REPOSITORY = HAS_AUTH_PREFIX + READ_REPOSITORY + HAS_AUTH_SUFFIX; + + /** + * Spring security eval hasAuthority expression to check if spring + * context contains {@link SpPermission#UPDATE_REPOSITORY}. + */ + public static final String HAS_AUTH_UPDATE_REPOSITORY = HAS_AUTH_PREFIX + UPDATE_REPOSITORY + HAS_AUTH_SUFFIX; + + /** + * Spring security eval hasAuthority expression to check if spring + * context contains {@link SpPermission#READ_REPOSITORY} and + * {@link SpPermission#READ_TARGET}. + */ + public static final String HAS_AUTH_READ_REPOSITORY_AND_READ_TARGET = HAS_AUTH_PREFIX + READ_REPOSITORY + + HAS_AUTH_SUFFIX + HAS_AUTH_AND + HAS_AUTH_PREFIX + READ_TARGET + HAS_AUTH_SUFFIX; + + /** + * Spring security eval hasAuthority expression to check if spring + * context contains {@link SpPermission#DOWNLOAD_REPOSITORY_ARTIFACT}. + */ + public static final String HAS_AUTH_DOWNLOAD_ARTIFACT = HAS_AUTH_PREFIX + DOWNLOAD_REPOSITORY_ARTIFACT + + HAS_AUTH_SUFFIX; + + /** + * Spring security eval hasAnyRole expression to check if the spring + * context contains the anoynmous role or the controller specific role + * {@link SpPermission#CONTROLLER_ROLE}. + */ + public static final String IS_CONTROLLER = "hasAnyRole('" + CONTROLLER_ROLE_ANONYMOUS + "', '" + CONTROLLER_ROLE + + "')"; + + /** + * Spring security eval hasAuthority expression to check if the spring + * context contains the role to allow controllers to download specific + * role {@link SpPermission#CONTROLLER_DOWNLOAD_ROLE}. + */ + public static final String HAS_CONTROLLER_DOWNLOAD = HAS_AUTH_PREFIX + CONTROLLER_DOWNLOAD_ROLE + + HAS_AUTH_SUFFIX; + /** * Spring security eval hasAnyRole expression to check if the spring * context contains system code role @@ -272,176 +359,47 @@ public final class SpPermission { /** * Spring security eval hasAuthority expression to check if spring - * context contains {@link SpPermission#UPDATE_TARGET} or - * {@link #IS_SYSTEM_CODE}. + * context contains {@link SpPermission#CREATE_REPOSITORY} and + * {@link SpPermission#CREATE_TARGET}. */ - public static final String HAS_AUTH_UPDATE_TARGET = HAS_AUTH_PREFIX + UPDATE_TARGET + HAS_AUTH_SUFFIX - + HAS_AUTH_OR + IS_SYSTEM_CODE; + public static final String HAS_AUTH_CREATE_REPOSITORY_AND_CREATE_TARGET = HAS_AUTH_PREFIX + CREATE_REPOSITORY + + HAS_AUTH_SUFFIX + HAS_AUTH_AND + HAS_AUTH_PREFIX + CREATE_TARGET + HAS_AUTH_SUFFIX; /** * Spring security eval hasAuthority expression to check if spring - * context contains {@link SpPermission#SYSTEM_ADMIN} or - * {@link #IS_SYSTEM_CODE}. + * context contains {@link SpPermission#ROLLOUT_MANAGEMENT} */ - public static final String HAS_AUTH_SYSTEM_ADMIN = HAS_AUTH_PREFIX + SYSTEM_ADMIN + HAS_AUTH_SUFFIX - + HAS_AUTH_OR + IS_SYSTEM_CODE; - - /** - * Spring security eval hasAuthority expression to check if spring - * context contains {@link SpPermission#READ_TARGET} or - * {@link #IS_SYSTEM_CODE}. - */ - public static final String HAS_AUTH_READ_TARGET = HAS_AUTH_PREFIX + READ_TARGET + HAS_AUTH_SUFFIX + HAS_AUTH_OR - + IS_SYSTEM_CODE; - - /** - * Spring security eval hasAuthority expression to check if spring - * context contains {@link SpPermission#READ_TARGET_SEC_TOKEN} or - * {@link #IS_SYSTEM_CODE}. - */ - public static final String HAS_AUTH_READ_TARGET_SEC_TOKEN = HAS_AUTH_PREFIX + READ_TARGET_SEC_TOKEN - + HAS_AUTH_SUFFIX + HAS_AUTH_OR + IS_SYSTEM_CODE; - - /** - * Spring security eval hasAuthority expression to check if spring - * context contains {@link SpPermission#CREATE_TARGET} or - * {@link #IS_SYSTEM_CODE}. - */ - public static final String HAS_AUTH_CREATE_TARGET = HAS_AUTH_PREFIX + CREATE_TARGET + HAS_AUTH_SUFFIX - + HAS_AUTH_OR + IS_SYSTEM_CODE; - - /** - * Spring security eval hasAuthority expression to check if spring - * context contains {@link SpPermission#DELETE_TARGET} or - * {@link #IS_SYSTEM_CODE}. - */ - public static final String HAS_AUTH_DELETE_TARGET = HAS_AUTH_PREFIX + DELETE_TARGET + HAS_AUTH_SUFFIX - + HAS_AUTH_OR + IS_SYSTEM_CODE; - - /** - * Spring security eval hasAuthority expression to check if spring - * context contains {@link SpPermission#READ_REPOSITORY} and - * {@link SpPermission#UPDATE_TARGET} or {@link #IS_SYSTEM_CODE}. - */ - public static final String HAS_AUTH_READ_REPOSITORY_AND_UPDATE_TARGET = BRACKET_OPEN + HAS_AUTH_PREFIX - + READ_REPOSITORY + HAS_AUTH_SUFFIX + HAS_AUTH_AND + HAS_AUTH_PREFIX + UPDATE_TARGET + HAS_AUTH_SUFFIX - + BRACKET_CLOSE + HAS_AUTH_OR + IS_SYSTEM_CODE; - - /** - * Spring security eval hasAuthority expression to check if spring - * context contains {@link SpPermission#CREATE_REPOSITORY} or - * {@link #IS_SYSTEM_CODE}. - */ - public static final String HAS_AUTH_CREATE_REPOSITORY = HAS_AUTH_PREFIX + CREATE_REPOSITORY + HAS_AUTH_SUFFIX - + HAS_AUTH_OR + IS_SYSTEM_CODE; - - /** - * Spring security eval hasAuthority expression to check if spring - * context contains {@link SpPermission#DELETE_REPOSITORY} or - * {@link #IS_SYSTEM_CODE}. - */ - public static final String HAS_AUTH_DELETE_REPOSITORY = HAS_AUTH_PREFIX + DELETE_REPOSITORY + HAS_AUTH_SUFFIX - + HAS_AUTH_OR + IS_SYSTEM_CODE; - - /** - * Spring security eval hasAuthority expression to check if spring - * context contains {@link SpPermission#READ_REPOSITORY} or - * {@link #IS_SYSTEM_CODE}. - */ - public static final String HAS_AUTH_READ_REPOSITORY = HAS_AUTH_PREFIX + READ_REPOSITORY + HAS_AUTH_SUFFIX - + HAS_AUTH_OR + IS_SYSTEM_CODE; - - /** - * Spring security eval hasAuthority expression to check if spring - * context contains {@link SpPermission#UPDATE_REPOSITORY} or - * {@link #IS_SYSTEM_CODE}. - */ - public static final String HAS_AUTH_UPDATE_REPOSITORY = HAS_AUTH_PREFIX + UPDATE_REPOSITORY + HAS_AUTH_SUFFIX - + HAS_AUTH_OR + IS_SYSTEM_CODE; - - /** - * Spring security eval hasAuthority expression to check if spring - * context contains {@link SpPermission#READ_REPOSITORY} and - * {@link SpPermission#READ_TARGET} or {@link #IS_SYSTEM_CODE}. - */ - public static final String HAS_AUTH_READ_REPOSITORY_AND_READ_TARGET = BRACKET_OPEN + HAS_AUTH_PREFIX - + READ_REPOSITORY + HAS_AUTH_SUFFIX + HAS_AUTH_AND + HAS_AUTH_PREFIX + READ_TARGET + HAS_AUTH_SUFFIX - + BRACKET_CLOSE + HAS_AUTH_OR + IS_SYSTEM_CODE; - - /** - * Spring security eval hasAuthority expression to check if spring - * context contains {@link SpPermission#DOWNLOAD_REPOSITORY_ARTIFACT} or - * {@link #IS_SYSTEM_CODE}. - */ - public static final String HAS_AUTH_DOWNLOAD_ARTIFACT = HAS_AUTH_PREFIX + DOWNLOAD_REPOSITORY_ARTIFACT - + HAS_AUTH_SUFFIX + HAS_AUTH_OR + IS_SYSTEM_CODE; - - /** - * Spring security eval hasAnyRole expression to check if the spring - * context contains the anoynmous role or the controller specific role - * {@link SpringEvalExpressions#CONTROLLER_ROLE}. - */ - public static final String IS_CONTROLLER = "hasAnyRole('" + CONTROLLER_ROLE_ANONYMOUS + "', '" + CONTROLLER_ROLE - + "')"; - - /** - * Spring security eval hasAuthority expression to check if the spring - * context contains the role to allow controllers to download specific - * role {@link SpringEvalExpressions#CONTROLLER_DOWNLOAD_ROLE} - */ - public static final String HAS_CONTROLLER_DOWNLOAD = HAS_AUTH_PREFIX + CONTROLLER_DOWNLOAD_ROLE + public static final String HAS_AUTH_ROLLOUT_MANAGEMENT_READ = HAS_AUTH_PREFIX + ROLLOUT_MANAGEMENT + HAS_AUTH_SUFFIX; /** * Spring security eval hasAuthority expression to check if spring - * context contains {@link SpPermission#CREATE_REPOSITORY} and - * {@link SpPermission#CREATE_TARGET} or {@link #IS_SYSTEM_CODE}. + * context contains {@link SpPermission#ROLLOUT_MANAGEMENT} and + * {@link SpPermission#READ_TARGET} */ - public static final String HAS_AUTH_CREATE_REPOSITORY_AND_CREATE_TARGET = BRACKET_OPEN + HAS_AUTH_PREFIX - + CREATE_REPOSITORY + HAS_AUTH_SUFFIX + HAS_AUTH_AND + HAS_AUTH_PREFIX + CREATE_TARGET + HAS_AUTH_SUFFIX - + BRACKET_CLOSE + HAS_AUTH_OR + IS_SYSTEM_CODE; - - /** - * Spring security eval hasAuthority expression to check if spring - * context contains {@link SpPermission#ROLLOUT_MANAGEMENT} or - * {@link #IS_SYSTEM_CODE}. - */ - public static final String HAS_AUTH_ROLLOUT_MANAGEMENT_READ = HAS_AUTH_PREFIX + ROLLOUT_MANAGEMENT - + HAS_AUTH_SUFFIX + HAS_AUTH_OR + IS_SYSTEM_CODE; + public static final String HAS_AUTH_ROLLOUT_MANAGEMENT_READ_AND_TARGET_READ = HAS_AUTH_PREFIX + + ROLLOUT_MANAGEMENT + HAS_AUTH_SUFFIX + HAS_AUTH_AND + HAS_AUTH_PREFIX + READ_TARGET + HAS_AUTH_SUFFIX; /** * Spring security eval hasAuthority expression to check if spring * context contains {@link SpPermission#ROLLOUT_MANAGEMENT} and - * {@link SpPermission#READ_TARGET} or {@link #IS_SYSTEM_CODE}. + * {@link SpPermission#UPDATE_TARGET}. */ - public static final String HAS_AUTH_ROLLOUT_MANAGEMENT_READ_AND_TARGET_READ = BRACKET_OPEN + HAS_AUTH_PREFIX - + ROLLOUT_MANAGEMENT + HAS_AUTH_SUFFIX + HAS_AUTH_AND + HAS_AUTH_PREFIX + READ_TARGET + HAS_AUTH_SUFFIX - + BRACKET_CLOSE + HAS_AUTH_OR + IS_SYSTEM_CODE; + public static final String HAS_AUTH_ROLLOUT_MANAGEMENT_WRITE = HAS_AUTH_PREFIX + ROLLOUT_MANAGEMENT + + HAS_AUTH_SUFFIX + HAS_AUTH_AND + HAS_AUTH_PREFIX + UPDATE_TARGET + HAS_AUTH_SUFFIX; /** * Spring security eval hasAuthority expression to check if spring - * context contains {@link SpPermission#ROLLOUT_MANAGEMENT} and - * {@link SpPermission#UPDATE_TARGET} or {@link #IS_SYSTEM_CODE}. - */ - public static final String HAS_AUTH_ROLLOUT_MANAGEMENT_WRITE = BRACKET_OPEN + HAS_AUTH_PREFIX - + ROLLOUT_MANAGEMENT + HAS_AUTH_SUFFIX + HAS_AUTH_AND + HAS_AUTH_PREFIX + UPDATE_TARGET - + HAS_AUTH_SUFFIX + BRACKET_CLOSE + HAS_AUTH_OR + IS_SYSTEM_CODE; - - /** - * Spring security eval hasAuthority expression to check if spring - * context contains {@link SpPermission#TENANT_CONFIGURATION} or - * {@link #IS_SYSTEM_CODE}. + * context contains {@link SpPermission#TENANT_CONFIGURATION} */ public static final String HAS_AUTH_TENANT_CONFIGURATION = HAS_AUTH_PREFIX + TENANT_CONFIGURATION - + HAS_AUTH_SUFFIX + HAS_AUTH_OR + IS_SYSTEM_CODE; + + HAS_AUTH_SUFFIX; /** * Spring security eval hasAuthority expression to check if spring - * context contains {@link SpPermission#SYSTEM_MONITOR} or - * {@link #IS_SYSTEM_CODE}. + * context contains {@link SpPermission#SYSTEM_MONITOR} */ - public static final String HAS_AUTH_SYSTEM_MONITOR = HAS_AUTH_PREFIX + SYSTEM_MONITOR + HAS_AUTH_SUFFIX - + HAS_AUTH_OR + IS_SYSTEM_CODE; + public static final String HAS_AUTH_SYSTEM_MONITOR = HAS_AUTH_PREFIX + SYSTEM_MONITOR + HAS_AUTH_SUFFIX; private SpringEvalExpressions() { // utility class diff --git a/hawkbit-security-core/src/main/java/org/eclipse/hawkbit/security/HawkbitSecurityProperties.java b/hawkbit-security-core/src/main/java/org/eclipse/hawkbit/security/HawkbitSecurityProperties.java index 3f0be994a..d6de1f80e 100644 --- a/hawkbit-security-core/src/main/java/org/eclipse/hawkbit/security/HawkbitSecurityProperties.java +++ b/hawkbit-security-core/src/main/java/org/eclipse/hawkbit/security/HawkbitSecurityProperties.java @@ -21,7 +21,6 @@ public class HawkbitSecurityProperties { private final Clients clients = new Clients(); private final Dos dos = new Dos(); - private final Xframe xframe = new Xframe(); public Dos getDos() { return dos; @@ -31,45 +30,6 @@ public class HawkbitSecurityProperties { return clients; } - public Xframe getXframe() { - return xframe; - } - - /** - * Defines the XFrameOption policy. - * - */ - public static class Xframe { - - /** - * XFrame option. Allowed values: SAMEORIGIN, DENY, ALLOW-FROM - */ - private String option = "DENY"; - - /** - * ALLOW-FROM defined URL, has to be filled in case ALLOW-FROM option is - * selected. - */ - private String allowfrom = ""; - - public String getOption() { - return option; - } - - public void setOption(final String option) { - this.option = option; - } - - public String getAllowfrom() { - return allowfrom; - } - - public void setAllowfrom(final String allowfrom) { - this.allowfrom = allowfrom; - } - - } - /** * Security configuration related to clients. * diff --git a/pom.xml b/pom.xml index 8426b9740..6ad36491b 100644 --- a/pom.xml +++ b/pom.xml @@ -14,7 +14,7 @@ org.springframework.boot spring-boot-starter-parent - 1.2.8.RELEASE + 1.3.6.RELEASE org.eclipse.hawkbit @@ -61,17 +61,13 @@ 1.8 - 1.2.8.RELEASE + 1.3.6.RELEASE - 2.5.5 - 5.2.4.Final 1.2.0.RELEASE 1.6.1.RELEASE - 0.18.0.RELEASE - Fowler-SR1 3.2.2 @@ -102,7 +98,7 @@ 0.9.1 19.0 1.4.3 - 1.50.2 + 1.50.5 1.18.1 2.2.4 1.1.7 From 17a8f01d84b69bf904c0d78f5bf889dbb048175e Mon Sep 17 00:00:00 2001 From: kaizimmerm Date: Mon, 11 Jul 2016 12:24:33 +0200 Subject: [PATCH 09/24] Fixed tests. Signed-off-by: kaizimmerm --- .../mgmt/rest/resource/MgmtTargetResourceTest.java | 4 ++-- .../rest/configuration/RestConfiguration.java | 3 +++ pom.xml | 13 ++++++------- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResourceTest.java b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResourceTest.java index 57e2c096d..8edb6aa86 100644 --- a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResourceTest.java +++ b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResourceTest.java @@ -139,10 +139,10 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest { public void securityTokenIsNotInResponseIfMissingPermission() throws Exception { final String knownControllerId = "knownControllerId"; - targetManagement.createTarget(entityFactory.generateTarget(knownControllerId)); + final Target createTarget = targetManagement.createTarget(entityFactory.generateTarget(knownControllerId)); mvc.perform(get(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/{targetId}", knownControllerId)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) - .andExpect(jsonPath("securityToken").doesNotExist()); + .andExpect(jsonPath("securityToken", equalTo(null))); } @Test diff --git a/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/configuration/RestConfiguration.java b/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/configuration/RestConfiguration.java index e2c4ec2a1..73f7eed76 100644 --- a/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/configuration/RestConfiguration.java +++ b/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/configuration/RestConfiguration.java @@ -17,12 +17,15 @@ import org.springframework.beans.factory.FactoryBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Scope; +import org.springframework.hateoas.config.EnableHypermediaSupport; +import org.springframework.hateoas.config.EnableHypermediaSupport.HypermediaType; import org.springframework.web.context.WebApplicationContext; /** * Configuration for Rest api. */ @Configuration +@EnableHypermediaSupport(type = { HypermediaType.HAL }) public class RestConfiguration { /** diff --git a/pom.xml b/pom.xml index 6ad36491b..c05f8c692 100644 --- a/pom.xml +++ b/pom.xml @@ -66,7 +66,13 @@ 1.2.0.RELEASE +<<<<<<< Upstream, based on master 1.6.1.RELEASE +======= + 1.6.0.RELEASE + 3.6.2 + 4.1.1.RELEASE +>>>>>>> e285495 Fixed tests. 3.2.2 @@ -99,7 +105,6 @@ 19.0 1.4.3 1.50.5 - 1.18.1 2.2.4 1.1.7 1.1 @@ -558,12 +563,6 @@ ${allure.version} test - - com.sun.jersey - jersey-client - ${jersey-client.version} - test - pl.pragmatists JUnitParams From 05c45d70d9b2359574355c949b9ec25a7f25a23a Mon Sep 17 00:00:00 2001 From: kaizimmerm Date: Sat, 16 Jul 2016 20:17:44 +0200 Subject: [PATCH 10/24] Removed enable auto configure from repo config Signed-off-by: kaizimmerm --- .../RepositoryApplicationConfiguration.java | 21 +------------------ .../test/util => }/TestConfiguration.java | 8 +++++-- .../test/util/AbstractIntegrationTest.java | 1 + 3 files changed, 8 insertions(+), 22 deletions(-) rename hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/{repository/test/util => }/TestConfiguration.java (92%) diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/RepositoryApplicationConfiguration.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/RepositoryApplicationConfiguration.java index f06d44516..c159bdc6b 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/RepositoryApplicationConfiguration.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/RepositoryApplicationConfiguration.java @@ -46,7 +46,6 @@ import org.eclipse.hawkbit.repository.jpa.aspects.ExceptionMappingAspectHandler; import org.eclipse.hawkbit.repository.jpa.configuration.MultiTenantJpaTransactionManager; import org.eclipse.hawkbit.repository.jpa.model.helper.AfterTransactionCommitExecutorHolder; import org.eclipse.hawkbit.repository.jpa.model.helper.CacheManagerHolder; -import org.eclipse.hawkbit.repository.jpa.model.helper.EntityInterceptorHolder; import org.eclipse.hawkbit.repository.jpa.model.helper.SecurityTokenGeneratorHolder; import org.eclipse.hawkbit.repository.jpa.model.helper.SystemManagementHolder; import org.eclipse.hawkbit.repository.jpa.model.helper.SystemSecurityContextHolder; @@ -55,8 +54,6 @@ import org.eclipse.hawkbit.repository.jpa.model.helper.TenantConfigurationManage import org.eclipse.hawkbit.security.SecurityTokenGenerator; import org.eclipse.hawkbit.security.SystemSecurityContext; import org.eclipse.hawkbit.tenancy.TenantAware; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration; import org.springframework.boot.context.properties.EnableConfigurationProperties; @@ -73,8 +70,6 @@ import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.annotation.EnableTransactionManagement; import org.springframework.validation.beanvalidation.MethodValidationPostProcessor; -import com.google.common.eventbus.EventBus; - /** * General configuration for hawkBit's Repository. * @@ -85,13 +80,9 @@ import com.google.common.eventbus.EventBus; @EnableAspectJAutoProxy @Configuration @ComponentScan -@EnableAutoConfiguration @EnableConfigurationProperties(RepositoryProperties.class) @EnableScheduling public class RepositoryApplicationConfiguration extends JpaBaseConfiguration { - @Autowired - private EventBus eventBus; - /** * @return the {@link SystemSecurityContext} singleton bean which make it * accessible in beans which cannot access the service directly, @@ -145,14 +136,6 @@ public class RepositoryApplicationConfiguration extends JpaBaseConfiguration { return SecurityTokenGeneratorHolder.getInstance(); } - /** - * @return the singleton instance of the {@link EntityInterceptorHolder} - */ - @Bean - public EntityInterceptorHolder entityInterceptorHolder() { - return EntityInterceptorHolder.getInstance(); - } - /** * @return the singleton instance of the {@link CacheManagerHolder} */ @@ -264,9 +247,7 @@ public class RepositoryApplicationConfiguration extends JpaBaseConfiguration { @Bean @ConditionalOnMissingBean public TenantStatsManagement tenantStatsManagement() { - final TenantStatsManagement mgmt = new JpaTenantStatsManagement(); - eventBus.register(mgmt); - return mgmt; + return new JpaTenantStatsManagement(); } /** diff --git a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/TestConfiguration.java b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/TestConfiguration.java similarity index 92% rename from hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/TestConfiguration.java rename to hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/TestConfiguration.java index dbdc0db82..499925540 100644 --- a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/TestConfiguration.java +++ b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/TestConfiguration.java @@ -6,22 +6,25 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository.test.util; +package org.eclipse.hawkbit; import java.util.concurrent.Executor; import java.util.concurrent.Executors; -import org.eclipse.hawkbit.HawkbitServerProperties; import org.eclipse.hawkbit.cache.CacheConstants; import org.eclipse.hawkbit.cache.TenancyCacheManager; import org.eclipse.hawkbit.cache.TenantAwareCacheManager; import org.eclipse.hawkbit.repository.jpa.model.helper.EventBusHolder; +import org.eclipse.hawkbit.repository.test.util.JpaTestRepositoryManagement; +import org.eclipse.hawkbit.repository.test.util.TestRepositoryManagement; +import org.eclipse.hawkbit.repository.test.util.TestdataFactory; import org.eclipse.hawkbit.security.DdiSecurityProperties; import org.eclipse.hawkbit.security.SecurityContextTenantAware; import org.eclipse.hawkbit.security.SpringSecurityAuditorAware; import org.eclipse.hawkbit.tenancy.TenantAware; import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler; import org.springframework.aop.interceptor.SimpleAsyncUncaughtExceptionHandler; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.cache.Cache; import org.springframework.cache.guava.GuavaCacheManager; @@ -48,6 +51,7 @@ import com.mongodb.MongoClientOptions; @EnableGlobalMethodSecurity(prePostEnabled = true, mode = AdviceMode.PROXY, proxyTargetClass = false, securedEnabled = true) @EnableConfigurationProperties({ HawkbitServerProperties.class, DdiSecurityProperties.class }) @Profile("test") +@EnableAutoConfiguration public class TestConfiguration implements AsyncConfigurer { @Bean public TestRepositoryManagement testRepositoryManagement() { diff --git a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/AbstractIntegrationTest.java b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/AbstractIntegrationTest.java index 127de332d..b8c99b57a 100644 --- a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/AbstractIntegrationTest.java +++ b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/AbstractIntegrationTest.java @@ -12,6 +12,7 @@ import static org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpre import static org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions.SYSTEM_ROLE; import org.eclipse.hawkbit.ExcludePathAwareShallowETagFilter; +import org.eclipse.hawkbit.TestConfiguration; import org.eclipse.hawkbit.repository.ArtifactManagement; import org.eclipse.hawkbit.repository.ControllerManagement; import org.eclipse.hawkbit.repository.DeploymentManagement; From 2153f627c68474b4b1b7685e3eff67ef8f1f9dc7 Mon Sep 17 00:00:00 2001 From: kaizimmerm Date: Thu, 21 Jul 2016 10:39:57 +0200 Subject: [PATCH 11/24] Using same plugin for weave and metamodel Signed-off-by: kaizimmerm --- .../hawkbit-repository-jpa/pom.xml | 53 ++++++------------- 1 file changed, 15 insertions(+), 38 deletions(-) diff --git a/hawkbit-repository/hawkbit-repository-jpa/pom.xml b/hawkbit-repository/hawkbit-repository-jpa/pom.xml index bd56e9ca5..24c90e28e 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/pom.xml +++ b/hawkbit-repository/hawkbit-repository-jpa/pom.xml @@ -1,14 +1,9 @@ - - + + 4.0.0 org.eclipse.hawkbit @@ -120,7 +115,7 @@ javax.el javax.el-api test - + ru.yandex.qatools.allure allure-junit-adaptor @@ -140,43 +135,25 @@ - - org.bsc.maven - maven-processor-plugin - - - process - - process - - generate-sources - - - org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor - - - - - - - org.hibernate - hibernate-jpamodelgen - ${hibernate.version} - - - com.ethlo.persistence.tools eclipselink-maven-plugin 2.6.2 + + modelgen + generate-sources + + modelgen + + process-classes weave - + From 7a38e212b6950f862170023543329114ed1e21fc Mon Sep 17 00:00:00 2001 From: kaizimmerm Date: Wed, 27 Jul 2016 14:51:18 +0200 Subject: [PATCH 12/24] Fixed license header and entity scan. Signed-off-by: kaizimmerm --- hawkbit-repository/hawkbit-repository-jpa/pom.xml | 14 ++++++++++---- .../RepositoryApplicationConfiguration.java | 2 ++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/hawkbit-repository/hawkbit-repository-jpa/pom.xml b/hawkbit-repository/hawkbit-repository-jpa/pom.xml index 24c90e28e..3646e97fc 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/pom.xml +++ b/hawkbit-repository/hawkbit-repository-jpa/pom.xml @@ -1,7 +1,13 @@ - + 4.0.0 diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/RepositoryApplicationConfiguration.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/RepositoryApplicationConfiguration.java index c159bdc6b..628af38e0 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/RepositoryApplicationConfiguration.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/RepositoryApplicationConfiguration.java @@ -57,6 +57,7 @@ import org.eclipse.hawkbit.tenancy.TenantAware; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration; import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.boot.orm.jpa.EntityScan; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; @@ -82,6 +83,7 @@ import org.springframework.validation.beanvalidation.MethodValidationPostProcess @ComponentScan @EnableConfigurationProperties(RepositoryProperties.class) @EnableScheduling +@EntityScan("org.eclipse.hawkbit.repository.jpa.model") public class RepositoryApplicationConfiguration extends JpaBaseConfiguration { /** * @return the {@link SystemSecurityContext} singleton bean which make it From 446957677945d1c53483e786bec89cf38240cf87 Mon Sep 17 00:00:00 2001 From: Kai Zimmermann Date: Thu, 18 Aug 2016 14:54:32 +0200 Subject: [PATCH 13/24] Upgarde boot and sec to newest patch version. Signed-off-by: Kai Zimmermann --- examples/hawkbit-example-app/pom.xml | 20 -------------------- pom.xml | 11 +++-------- 2 files changed, 3 insertions(+), 28 deletions(-) diff --git a/examples/hawkbit-example-app/pom.xml b/examples/hawkbit-example-app/pom.xml index f501d5529..15d802792 100644 --- a/examples/hawkbit-example-app/pom.xml +++ b/examples/hawkbit-example-app/pom.xml @@ -107,26 +107,6 @@ org.springframework.boot spring-boot-starter - - - org.apache.logging.log4j - log4j-api - - - - org.slf4j - jul-to-slf4j - - - - org.slf4j - jcl-over-slf4j - - - - org.slf4j - log4j-over-slf4j - org.springframework.security spring-security-aspects diff --git a/pom.xml b/pom.xml index c05f8c692..899e3abbd 100644 --- a/pom.xml +++ b/pom.xml @@ -14,7 +14,7 @@ org.springframework.boot spring-boot-starter-parent - 1.3.6.RELEASE + 1.3.7.RELEASE org.eclipse.hawkbit @@ -61,18 +61,13 @@ 1.8 - 1.3.6.RELEASE + 1.3.7.RELEASE 1.2.0.RELEASE -<<<<<<< Upstream, based on master 1.6.1.RELEASE -======= - 1.6.0.RELEASE - 3.6.2 - 4.1.1.RELEASE ->>>>>>> e285495 Fixed tests. + 4.1.2.RELEASE 3.2.2 From aff23501860e1fbbd64fda9ce912078353c235d9 Mon Sep 17 00:00:00 2001 From: kaizimmerm Date: Fri, 19 Aug 2016 14:22:43 +0200 Subject: [PATCH 14/24] Fix simulator log config. Signed-off-by: kaizimmerm --- .../src/main/resources/{logback.xml => logback-spring.xml} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename examples/hawkbit-device-simulator/src/main/resources/{logback.xml => logback-spring.xml} (96%) diff --git a/examples/hawkbit-device-simulator/src/main/resources/logback.xml b/examples/hawkbit-device-simulator/src/main/resources/logback-spring.xml similarity index 96% rename from examples/hawkbit-device-simulator/src/main/resources/logback.xml rename to examples/hawkbit-device-simulator/src/main/resources/logback-spring.xml index 5f3f1dbef..355284d39 100644 --- a/examples/hawkbit-device-simulator/src/main/resources/logback.xml +++ b/examples/hawkbit-device-simulator/src/main/resources/logback-spring.xml @@ -22,7 +22,7 @@ - + \ No newline at end of file From 00539ea49c2a291f05204ebafbde34ba7f07944d Mon Sep 17 00:00:00 2001 From: kaizimmerm Date: Wed, 24 Aug 2016 10:58:03 +0200 Subject: [PATCH 15/24] Merges with master Signed-off-by: kaizimmerm --- .../resource/DdiArtifactDownloadTest.java | 2 +- .../im/authentication/SpPermission.java | 272 ++++++++++-------- 2 files changed, 158 insertions(+), 116 deletions(-) diff --git a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactDownloadTest.java b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactDownloadTest.java index d8931ab41..cf8314de2 100644 --- a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactDownloadTest.java +++ b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactDownloadTest.java @@ -29,7 +29,7 @@ import java.util.List; import java.util.TimeZone; import org.apache.commons.lang3.RandomUtils; -import org.eclipse.hawkbit.eventbus.event.DownloadProgressEvent; +import org.eclipse.hawkbit.repository.eventbus.event.DownloadProgressEvent; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.Status; import org.eclipse.hawkbit.repository.model.Artifact; diff --git a/hawkbit-security-core/src/main/java/org/eclipse/hawkbit/im/authentication/SpPermission.java b/hawkbit-security-core/src/main/java/org/eclipse/hawkbit/im/authentication/SpPermission.java index 6a68aee5b..866ee16bc 100644 --- a/hawkbit-security-core/src/main/java/org/eclipse/hawkbit/im/authentication/SpPermission.java +++ b/hawkbit-security-core/src/main/java/org/eclipse/hawkbit/im/authentication/SpPermission.java @@ -185,18 +185,22 @@ public final class SpPermission { field.setAccessible(true); try { final String role = (String) field.get(null); - if (!(exclusionRoles.contains(role))) { - allPermissions.add(role); - } + addIfNotExcluded(exclusionRoles, allPermissions, role); } catch (final IllegalAccessException e) { LOGGER.error(e.getMessage(), e); } - } } return allPermissions; } + private static void addIfNotExcluded(final Collection exclusionRoles, final List allPermissions, + final String role) { + if (!(exclusionRoles.contains(role))) { + allPermissions.add(role); + } + } + /** * Contains all the spring security evaluation expressions for the * {@link PreAuthorize} annotation for method security. @@ -224,8 +228,10 @@ public final class SpPermission { /* * Spring security eval expressions. */ - private static final String HAS_AUTH_PREFIX = "hasAuthority('"; - private static final String HAS_AUTH_SUFFIX = "')"; + private static final String BRACKET_OPEN = "("; + private static final String BRACKET_CLOSE = ")"; + private static final String HAS_AUTH_PREFIX = "hasAuthority" + BRACKET_OPEN + "'"; + private static final String HAS_AUTH_SUFFIX = "'" + BRACKET_CLOSE; private static final String HAS_AUTH_AND = " and "; /** @@ -257,99 +263,6 @@ public final class SpPermission { */ public static final String HAS_AUTH_OR = " or "; - /** - * Spring security eval hasAuthority expression to check if spring - * context contains {@link SpPermission#UPDATE_TARGET}. - */ - public static final String HAS_AUTH_UPDATE_TARGET = HAS_AUTH_PREFIX + UPDATE_TARGET + HAS_AUTH_SUFFIX; - - /** - * Spring security eval hasAuthority expression to check if spring - * context contains {@link SpPermission#SYSTEM_ADMIN}. - */ - public static final String HAS_AUTH_SYSTEM_ADMIN = HAS_AUTH_PREFIX + SYSTEM_ADMIN + HAS_AUTH_SUFFIX; - - /** - * Spring security eval hasAuthority expression to check if spring - * context contains {@link SpPermission#READ_TARGET}. - */ - public static final String HAS_AUTH_READ_TARGET = HAS_AUTH_PREFIX + READ_TARGET + HAS_AUTH_SUFFIX; - - /** - * Spring security eval hasAuthority expression to check if spring - * context contains {@link SpPermission#CREATE_TARGET}. - */ - public static final String HAS_AUTH_CREATE_TARGET = HAS_AUTH_PREFIX + CREATE_TARGET + HAS_AUTH_SUFFIX; - - /** - * Spring security eval hasAuthority expression to check if spring - * context contains {@link SpPermission#DELETE_TARGET}. - */ - public static final String HAS_AUTH_DELETE_TARGET = HAS_AUTH_PREFIX + DELETE_TARGET + HAS_AUTH_SUFFIX; - - /** - * Spring security eval hasAuthority expression to check if spring - * context contains {@link SpPermission#READ_REPOSITORY} and - * {@link SpPermission#UPDATE_TARGET}. - */ - public static final String HAS_AUTH_READ_REPOSITORY_AND_UPDATE_TARGET = HAS_AUTH_PREFIX + READ_REPOSITORY - + HAS_AUTH_SUFFIX + HAS_AUTH_AND + HAS_AUTH_PREFIX + UPDATE_TARGET + HAS_AUTH_SUFFIX; - - /** - * Spring security eval hasAuthority expression to check if spring - * context contains {@link SpPermission#CREATE_REPOSITORY}. - */ - public static final String HAS_AUTH_CREATE_REPOSITORY = HAS_AUTH_PREFIX + CREATE_REPOSITORY + HAS_AUTH_SUFFIX; - - /** - * Spring security eval hasAuthority expression to check if spring - * context contains {@link SpPermission#DELETE_REPOSITORY}. - */ - public static final String HAS_AUTH_DELETE_REPOSITORY = HAS_AUTH_PREFIX + DELETE_REPOSITORY + HAS_AUTH_SUFFIX; - - /** - * Spring security eval hasAuthority expression to check if spring - * context contains {@link SpPermission#READ_REPOSITORY}. - */ - public static final String HAS_AUTH_READ_REPOSITORY = HAS_AUTH_PREFIX + READ_REPOSITORY + HAS_AUTH_SUFFIX; - - /** - * Spring security eval hasAuthority expression to check if spring - * context contains {@link SpPermission#UPDATE_REPOSITORY}. - */ - public static final String HAS_AUTH_UPDATE_REPOSITORY = HAS_AUTH_PREFIX + UPDATE_REPOSITORY + HAS_AUTH_SUFFIX; - - /** - * Spring security eval hasAuthority expression to check if spring - * context contains {@link SpPermission#READ_REPOSITORY} and - * {@link SpPermission#READ_TARGET}. - */ - public static final String HAS_AUTH_READ_REPOSITORY_AND_READ_TARGET = HAS_AUTH_PREFIX + READ_REPOSITORY - + HAS_AUTH_SUFFIX + HAS_AUTH_AND + HAS_AUTH_PREFIX + READ_TARGET + HAS_AUTH_SUFFIX; - - /** - * Spring security eval hasAuthority expression to check if spring - * context contains {@link SpPermission#DOWNLOAD_REPOSITORY_ARTIFACT}. - */ - public static final String HAS_AUTH_DOWNLOAD_ARTIFACT = HAS_AUTH_PREFIX + DOWNLOAD_REPOSITORY_ARTIFACT - + HAS_AUTH_SUFFIX; - - /** - * Spring security eval hasAnyRole expression to check if the spring - * context contains the anoynmous role or the controller specific role - * {@link SpPermission#CONTROLLER_ROLE}. - */ - public static final String IS_CONTROLLER = "hasAnyRole('" + CONTROLLER_ROLE_ANONYMOUS + "', '" + CONTROLLER_ROLE - + "')"; - - /** - * Spring security eval hasAuthority expression to check if the spring - * context contains the role to allow controllers to download specific - * role {@link SpPermission#CONTROLLER_DOWNLOAD_ROLE}. - */ - public static final String HAS_CONTROLLER_DOWNLOAD = HAS_AUTH_PREFIX + CONTROLLER_DOWNLOAD_ROLE - + HAS_AUTH_SUFFIX; - /** * Spring security eval hasAnyRole expression to check if the spring * context contains system code role @@ -359,47 +272,176 @@ public final class SpPermission { /** * Spring security eval hasAuthority expression to check if spring - * context contains {@link SpPermission#CREATE_REPOSITORY} and - * {@link SpPermission#CREATE_TARGET}. + * context contains {@link SpPermission#UPDATE_TARGET} or + * {@link #IS_SYSTEM_CODE}. */ - public static final String HAS_AUTH_CREATE_REPOSITORY_AND_CREATE_TARGET = HAS_AUTH_PREFIX + CREATE_REPOSITORY - + HAS_AUTH_SUFFIX + HAS_AUTH_AND + HAS_AUTH_PREFIX + CREATE_TARGET + HAS_AUTH_SUFFIX; + public static final String HAS_AUTH_UPDATE_TARGET = HAS_AUTH_PREFIX + UPDATE_TARGET + HAS_AUTH_SUFFIX + + HAS_AUTH_OR + IS_SYSTEM_CODE; /** * Spring security eval hasAuthority expression to check if spring - * context contains {@link SpPermission#ROLLOUT_MANAGEMENT} + * context contains {@link SpPermission#SYSTEM_ADMIN} or + * {@link #IS_SYSTEM_CODE}. + */ + public static final String HAS_AUTH_SYSTEM_ADMIN = HAS_AUTH_PREFIX + SYSTEM_ADMIN + HAS_AUTH_SUFFIX + + HAS_AUTH_OR + IS_SYSTEM_CODE; + + /** + * Spring security eval hasAuthority expression to check if spring + * context contains {@link SpPermission#READ_TARGET} or + * {@link #IS_SYSTEM_CODE}. + */ + public static final String HAS_AUTH_READ_TARGET = HAS_AUTH_PREFIX + READ_TARGET + HAS_AUTH_SUFFIX + HAS_AUTH_OR + + IS_SYSTEM_CODE; + + /** + * Spring security eval hasAuthority expression to check if spring + * context contains {@link SpPermission#READ_TARGET_SEC_TOKEN} or + * {@link #IS_SYSTEM_CODE}. + */ + public static final String HAS_AUTH_READ_TARGET_SEC_TOKEN = HAS_AUTH_PREFIX + READ_TARGET_SEC_TOKEN + + HAS_AUTH_SUFFIX + HAS_AUTH_OR + IS_SYSTEM_CODE; + + /** + * Spring security eval hasAuthority expression to check if spring + * context contains {@link SpPermission#CREATE_TARGET} or + * {@link #IS_SYSTEM_CODE}. + */ + public static final String HAS_AUTH_CREATE_TARGET = HAS_AUTH_PREFIX + CREATE_TARGET + HAS_AUTH_SUFFIX + + HAS_AUTH_OR + IS_SYSTEM_CODE; + + /** + * Spring security eval hasAuthority expression to check if spring + * context contains {@link SpPermission#DELETE_TARGET} or + * {@link #IS_SYSTEM_CODE}. + */ + public static final String HAS_AUTH_DELETE_TARGET = HAS_AUTH_PREFIX + DELETE_TARGET + HAS_AUTH_SUFFIX + + HAS_AUTH_OR + IS_SYSTEM_CODE; + + /** + * Spring security eval hasAuthority expression to check if spring + * context contains {@link SpPermission#READ_REPOSITORY} and + * {@link SpPermission#UPDATE_TARGET} or {@link #IS_SYSTEM_CODE}. + */ + public static final String HAS_AUTH_READ_REPOSITORY_AND_UPDATE_TARGET = BRACKET_OPEN + HAS_AUTH_PREFIX + + READ_REPOSITORY + HAS_AUTH_SUFFIX + HAS_AUTH_AND + HAS_AUTH_PREFIX + UPDATE_TARGET + HAS_AUTH_SUFFIX + + BRACKET_CLOSE + HAS_AUTH_OR + IS_SYSTEM_CODE; + + /** + * Spring security eval hasAuthority expression to check if spring + * context contains {@link SpPermission#CREATE_REPOSITORY} or + * {@link #IS_SYSTEM_CODE}. + */ + public static final String HAS_AUTH_CREATE_REPOSITORY = HAS_AUTH_PREFIX + CREATE_REPOSITORY + HAS_AUTH_SUFFIX + + HAS_AUTH_OR + IS_SYSTEM_CODE; + + /** + * Spring security eval hasAuthority expression to check if spring + * context contains {@link SpPermission#DELETE_REPOSITORY} or + * {@link #IS_SYSTEM_CODE}. + */ + public static final String HAS_AUTH_DELETE_REPOSITORY = HAS_AUTH_PREFIX + DELETE_REPOSITORY + HAS_AUTH_SUFFIX + + HAS_AUTH_OR + IS_SYSTEM_CODE; + + /** + * Spring security eval hasAuthority expression to check if spring + * context contains {@link SpPermission#READ_REPOSITORY} or + * {@link #IS_SYSTEM_CODE}. + */ + public static final String HAS_AUTH_READ_REPOSITORY = HAS_AUTH_PREFIX + READ_REPOSITORY + HAS_AUTH_SUFFIX + + HAS_AUTH_OR + IS_SYSTEM_CODE; + + /** + * Spring security eval hasAuthority expression to check if spring + * context contains {@link SpPermission#UPDATE_REPOSITORY} or + * {@link #IS_SYSTEM_CODE}. + */ + public static final String HAS_AUTH_UPDATE_REPOSITORY = HAS_AUTH_PREFIX + UPDATE_REPOSITORY + HAS_AUTH_SUFFIX + + HAS_AUTH_OR + IS_SYSTEM_CODE; + + /** + * Spring security eval hasAuthority expression to check if spring + * context contains {@link SpPermission#READ_REPOSITORY} and + * {@link SpPermission#READ_TARGET} or {@link #IS_SYSTEM_CODE}. + */ + public static final String HAS_AUTH_READ_REPOSITORY_AND_READ_TARGET = BRACKET_OPEN + HAS_AUTH_PREFIX + + READ_REPOSITORY + HAS_AUTH_SUFFIX + HAS_AUTH_AND + HAS_AUTH_PREFIX + READ_TARGET + HAS_AUTH_SUFFIX + + BRACKET_CLOSE + HAS_AUTH_OR + IS_SYSTEM_CODE; + + /** + * Spring security eval hasAuthority expression to check if spring + * context contains {@link SpPermission#DOWNLOAD_REPOSITORY_ARTIFACT} or + * {@link #IS_SYSTEM_CODE}. + */ + public static final String HAS_AUTH_DOWNLOAD_ARTIFACT = HAS_AUTH_PREFIX + DOWNLOAD_REPOSITORY_ARTIFACT + + HAS_AUTH_SUFFIX + HAS_AUTH_OR + IS_SYSTEM_CODE; + + /** + * Spring security eval hasAnyRole expression to check if the spring + * context contains the anoynmous role or the controller specific role + * {@link SpringEvalExpressions#CONTROLLER_ROLE}. + */ + public static final String IS_CONTROLLER = "hasAnyRole('" + CONTROLLER_ROLE_ANONYMOUS + "', '" + CONTROLLER_ROLE + + "')"; + + /** + * Spring security eval hasAuthority expression to check if the spring + * context contains the role to allow controllers to download specific + * role {@link SpringEvalExpressions#CONTROLLER_DOWNLOAD_ROLE} + */ + public static final String HAS_CONTROLLER_DOWNLOAD = HAS_AUTH_PREFIX + CONTROLLER_DOWNLOAD_ROLE + + HAS_AUTH_SUFFIX; + + /** + * Spring security eval hasAuthority expression to check if spring + * context contains {@link SpPermission#CREATE_REPOSITORY} and + * {@link SpPermission#CREATE_TARGET} or {@link #IS_SYSTEM_CODE}. + */ + public static final String HAS_AUTH_CREATE_REPOSITORY_AND_CREATE_TARGET = BRACKET_OPEN + HAS_AUTH_PREFIX + + CREATE_REPOSITORY + HAS_AUTH_SUFFIX + HAS_AUTH_AND + HAS_AUTH_PREFIX + CREATE_TARGET + HAS_AUTH_SUFFIX + + BRACKET_CLOSE + HAS_AUTH_OR + IS_SYSTEM_CODE; + + /** + * Spring security eval hasAuthority expression to check if spring + * context contains {@link SpPermission#ROLLOUT_MANAGEMENT} or + * {@link #IS_SYSTEM_CODE}. */ public static final String HAS_AUTH_ROLLOUT_MANAGEMENT_READ = HAS_AUTH_PREFIX + ROLLOUT_MANAGEMENT - + HAS_AUTH_SUFFIX; + + HAS_AUTH_SUFFIX + HAS_AUTH_OR + IS_SYSTEM_CODE; /** * Spring security eval hasAuthority expression to check if spring * context contains {@link SpPermission#ROLLOUT_MANAGEMENT} and - * {@link SpPermission#READ_TARGET} + * {@link SpPermission#READ_TARGET} or {@link #IS_SYSTEM_CODE}. */ - public static final String HAS_AUTH_ROLLOUT_MANAGEMENT_READ_AND_TARGET_READ = HAS_AUTH_PREFIX - + ROLLOUT_MANAGEMENT + HAS_AUTH_SUFFIX + HAS_AUTH_AND + HAS_AUTH_PREFIX + READ_TARGET + HAS_AUTH_SUFFIX; + public static final String HAS_AUTH_ROLLOUT_MANAGEMENT_READ_AND_TARGET_READ = BRACKET_OPEN + HAS_AUTH_PREFIX + + ROLLOUT_MANAGEMENT + HAS_AUTH_SUFFIX + HAS_AUTH_AND + HAS_AUTH_PREFIX + READ_TARGET + HAS_AUTH_SUFFIX + + BRACKET_CLOSE + HAS_AUTH_OR + IS_SYSTEM_CODE; /** * Spring security eval hasAuthority expression to check if spring * context contains {@link SpPermission#ROLLOUT_MANAGEMENT} and - * {@link SpPermission#UPDATE_TARGET}. + * {@link SpPermission#UPDATE_TARGET} or {@link #IS_SYSTEM_CODE}. */ - public static final String HAS_AUTH_ROLLOUT_MANAGEMENT_WRITE = HAS_AUTH_PREFIX + ROLLOUT_MANAGEMENT - + HAS_AUTH_SUFFIX + HAS_AUTH_AND + HAS_AUTH_PREFIX + UPDATE_TARGET + HAS_AUTH_SUFFIX; + public static final String HAS_AUTH_ROLLOUT_MANAGEMENT_WRITE = BRACKET_OPEN + HAS_AUTH_PREFIX + + ROLLOUT_MANAGEMENT + HAS_AUTH_SUFFIX + HAS_AUTH_AND + HAS_AUTH_PREFIX + UPDATE_TARGET + + HAS_AUTH_SUFFIX + BRACKET_CLOSE + HAS_AUTH_OR + IS_SYSTEM_CODE; /** * Spring security eval hasAuthority expression to check if spring - * context contains {@link SpPermission#TENANT_CONFIGURATION} + * context contains {@link SpPermission#TENANT_CONFIGURATION} or + * {@link #IS_SYSTEM_CODE}. */ public static final String HAS_AUTH_TENANT_CONFIGURATION = HAS_AUTH_PREFIX + TENANT_CONFIGURATION - + HAS_AUTH_SUFFIX; + + HAS_AUTH_SUFFIX + HAS_AUTH_OR + IS_SYSTEM_CODE; /** * Spring security eval hasAuthority expression to check if spring - * context contains {@link SpPermission#SYSTEM_MONITOR} + * context contains {@link SpPermission#SYSTEM_MONITOR} or + * {@link #IS_SYSTEM_CODE}. */ - public static final String HAS_AUTH_SYSTEM_MONITOR = HAS_AUTH_PREFIX + SYSTEM_MONITOR + HAS_AUTH_SUFFIX; + public static final String HAS_AUTH_SYSTEM_MONITOR = HAS_AUTH_PREFIX + SYSTEM_MONITOR + HAS_AUTH_SUFFIX + + HAS_AUTH_OR + IS_SYSTEM_CODE; private SpringEvalExpressions() { // utility class From 2e0208f0542a822e20f40dc2dda777b5b482983b Mon Sep 17 00:00:00 2001 From: Kai Zimmermann Date: Wed, 24 Aug 2016 11:35:02 +0200 Subject: [PATCH 16/24] Fixed test after merge Signed-off-by: Kai Zimmermann --- .../resource/DdiArtifactDownloadTest.java | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactDownloadTest.java b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactDownloadTest.java index 81be97b7c..c618fa667 100644 --- a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactDownloadTest.java +++ b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactDownloadTest.java @@ -21,9 +21,12 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.nio.charset.StandardCharsets; +import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Arrays; +import java.util.Date; import java.util.List; +import java.util.TimeZone; import org.apache.commons.lang3.RandomUtils; import org.eclipse.hawkbit.repository.eventbus.event.DownloadProgressEvent; @@ -35,6 +38,7 @@ import org.eclipse.hawkbit.repository.model.LocalArtifact; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.test.util.WithUser; import org.eclipse.hawkbit.rest.AbstractRestIntegrationTestWithMongoDB; +import org.junit.Before; import org.junit.Test; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -69,6 +73,13 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong private volatile long shippedBytes = 0; private volatile long shippedBytesTotal = 0; + private final SimpleDateFormat dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz"); + + @Before + public void setup() { + dateFormat.setTimeZone(TimeZone.getTimeZone("GMT")); + } + @Autowired private EventBus eventBus; @@ -273,7 +284,7 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong ds.findFirstModuleByType(osType).getId(), artifact.getFilename())) .andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_OCTET_STREAM)) .andExpect(header().string("Accept-Ranges", "bytes")) - .andExpect(header().longValue("Last-Modified", artifact.getCreatedAt())) + .andExpect(header().string("Last-Modified", dateFormat.format(new Date(artifact.getCreatedAt())))) .andExpect(header().string("Content-Disposition", "attachment;filename=" + artifact.getFilename())) .andReturn(); @@ -386,7 +397,7 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong .andExpect(status().isOk()).andExpect(header().string("ETag", artifact.getSha1Hash())) .andExpect(content().contentType(MediaType.APPLICATION_OCTET_STREAM)) .andExpect(header().string("Accept-Ranges", "bytes")) - .andExpect(header().longValue("Last-Modified", artifact.getCreatedAt())) + .andExpect(header().string("Last-Modified", dateFormat.format(new Date(artifact.getCreatedAt())))) .andExpect(header().string("Content-Disposition", "attachment;filename=file1")).andReturn(); assertTrue("The same file that was uploaded is expected when downloaded", @@ -444,7 +455,7 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong .andExpect(status().isPartialContent()).andExpect(header().string("ETag", artifact.getSha1Hash())) .andExpect(content().contentType(MediaType.APPLICATION_OCTET_STREAM)) .andExpect(header().string("Accept-Ranges", "bytes")) - .andExpect(header().longValue("Last-Modified", artifact.getCreatedAt())) + .andExpect(header().string("Last-Modified", dateFormat.format(new Date(artifact.getCreatedAt())))) .andExpect(header().longValue("Content-Length", range)) .andExpect(header().string("Content-Range", "bytes " + rangeString + "/" + resultLength)) .andExpect(header().string("Content-Disposition", "attachment;filename=file1")).andReturn(); @@ -461,7 +472,7 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong .andExpect(status().isPartialContent()).andExpect(header().string("ETag", artifact.getSha1Hash())) .andExpect(content().contentType(MediaType.APPLICATION_OCTET_STREAM)) .andExpect(header().string("Accept-Ranges", "bytes")) - .andExpect(header().longValue("Last-Modified", artifact.getCreatedAt())) + .andExpect(header().string("Last-Modified", dateFormat.format(new Date(artifact.getCreatedAt())))) .andExpect(header().longValue("Content-Length", 1000)) .andExpect(header().string("Content-Range", "bytes " + (resultLength - 1000) + "-" + (resultLength - 1) + "/" + resultLength)) @@ -477,7 +488,7 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong .andExpect(status().isPartialContent()).andExpect(header().string("ETag", artifact.getSha1Hash())) .andExpect(content().contentType(MediaType.APPLICATION_OCTET_STREAM)) .andExpect(header().string("Accept-Ranges", "bytes")) - .andExpect(header().longValue("Last-Modified", artifact.getCreatedAt())) + .andExpect(header().string("Last-Modified", dateFormat.format(new Date(artifact.getCreatedAt())))) .andExpect(header().longValue("Content-Length", resultLength - 1000)) .andExpect(header().string("Content-Range", "bytes " + 1000 + "-" + (resultLength - 1) + "/" + resultLength)) @@ -493,7 +504,7 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong .andExpect(status().isPartialContent()).andExpect(header().string("ETag", artifact.getSha1Hash())) .andExpect(content().contentType("multipart/byteranges; boundary=THIS_STRING_SEPARATES_MULTIPART")) .andExpect(header().string("Accept-Ranges", "bytes")) - .andExpect(header().longValue("Last-Modified", artifact.getCreatedAt())) + .andExpect(header().string("Last-Modified", dateFormat.format(new Date(artifact.getCreatedAt())))) .andExpect(header().string("Content-Disposition", "attachment;filename=file1")).andReturn(); outputStream.reset(); From 9eee1985e250ff3bc93ee16ba8778d6dcecdd278 Mon Sep 17 00:00:00 2001 From: kaizimmerm Date: Thu, 25 Aug 2016 14:55:13 +0200 Subject: [PATCH 17/24] Upgrade jackson. Signed-off-by: kaizimmerm --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 0f4270afc..c9105f511 100644 --- a/pom.xml +++ b/pom.xml @@ -65,9 +65,9 @@ - 1.2.0.RELEASE 1.6.1.RELEASE 4.1.2.RELEASE + 2.8.1 3.2.2 From 0b0503a77fe0ce1de922eec1000de253fa97d1b4 Mon Sep 17 00:00:00 2001 From: Kai Zimmermann Date: Thu, 25 Aug 2016 15:19:53 +0200 Subject: [PATCH 18/24] Fixed locale problem on non EN systems Signed-off-by: Kai Zimmermann --- .../hawkbit/ddi/rest/resource/DdiArtifactDownloadTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactDownloadTest.java b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactDownloadTest.java index c618fa667..c0958c947 100644 --- a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactDownloadTest.java +++ b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactDownloadTest.java @@ -26,6 +26,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Date; import java.util.List; +import java.util.Locale; import java.util.TimeZone; import org.apache.commons.lang3.RandomUtils; @@ -73,7 +74,7 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong private volatile long shippedBytes = 0; private volatile long shippedBytesTotal = 0; - private final SimpleDateFormat dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz"); + private final SimpleDateFormat dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.ENGLISH); @Before public void setup() { From f779b3aba77a9b24b18301792d8092ac892ee7b1 Mon Sep 17 00:00:00 2001 From: Kai Zimmermann Date: Fri, 26 Aug 2016 09:15:08 +0200 Subject: [PATCH 19/24] removed unneeded override Signed-off-by: Kai Zimmermann --- pom.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/pom.xml b/pom.xml index 0f4270afc..e952f15bd 100644 --- a/pom.xml +++ b/pom.xml @@ -65,7 +65,6 @@ - 1.2.0.RELEASE 1.6.1.RELEASE 4.1.2.RELEASE From 16f4654ce00b3b33ae65b9b73d9c8eea5909e0f0 Mon Sep 17 00:00:00 2001 From: Kai Zimmermann Date: Mon, 29 Aug 2016 10:31:28 +0200 Subject: [PATCH 20/24] Removed Jackson version override Signed-off-by: Kai Zimmermann --- pom.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/pom.xml b/pom.xml index c9105f511..e952f15bd 100644 --- a/pom.xml +++ b/pom.xml @@ -67,7 +67,6 @@ 1.6.1.RELEASE 4.1.2.RELEASE - 2.8.1 3.2.2 From a71179b5faa93cedf698d80761ea4676acfa52cb Mon Sep 17 00:00:00 2001 From: SirWayne Date: Mon, 29 Aug 2016 11:04:49 +0200 Subject: [PATCH 21/24] Remove abstract mongo db test class, because every test starts a mongo. This class is not necessary Signed-off-by: SirWayne --- .../AmqpMessageDispatcherServiceTest.java | 4 +-- .../PropertyBasedArtifactUrlHandlerTest.java | 4 +-- ...AbstractJpaIntegrationTestWithMongoDB.java | 4 +-- .../test/util/AbstractIntegrationTest.java | 15 ++++++++ .../AbstractIntegrationTestWithMongoDB.java | 34 ------------------- ...bstractRestIntegrationTestWithMongoDB.java | 4 +-- 6 files changed, 23 insertions(+), 42 deletions(-) delete mode 100644 hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/AbstractIntegrationTestWithMongoDB.java diff --git a/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherServiceTest.java b/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherServiceTest.java index 103dc6c57..ee9f2b528 100644 --- a/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherServiceTest.java +++ b/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherServiceTest.java @@ -37,7 +37,7 @@ import org.eclipse.hawkbit.repository.model.Artifact; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.LocalArtifact; import org.eclipse.hawkbit.repository.model.SoftwareModule; -import org.eclipse.hawkbit.repository.test.util.AbstractIntegrationTestWithMongoDB; +import org.eclipse.hawkbit.repository.test.util.AbstractIntegrationTest; import org.eclipse.hawkbit.util.IpUtil; import org.junit.Test; import org.mockito.ArgumentCaptor; @@ -58,7 +58,7 @@ import ru.yandex.qatools.allure.annotations.Stories; @Features("Component Tests - Device Management Federation API") @Stories("AmqpMessage Dispatcher Service Test") @SpringApplicationConfiguration(classes = { org.eclipse.hawkbit.RepositoryApplicationConfiguration.class }) -public class AmqpMessageDispatcherServiceTest extends AbstractIntegrationTestWithMongoDB { +public class AmqpMessageDispatcherServiceTest extends AbstractIntegrationTest { private static final String TENANT = "default"; diff --git a/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/util/PropertyBasedArtifactUrlHandlerTest.java b/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/util/PropertyBasedArtifactUrlHandlerTest.java index 92e8f390d..ea01bc0ec 100644 --- a/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/util/PropertyBasedArtifactUrlHandlerTest.java +++ b/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/util/PropertyBasedArtifactUrlHandlerTest.java @@ -16,7 +16,7 @@ import org.eclipse.hawkbit.api.UrlProtocol; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.LocalArtifact; import org.eclipse.hawkbit.repository.model.SoftwareModule; -import org.eclipse.hawkbit.repository.test.util.AbstractIntegrationTestWithMongoDB; +import org.eclipse.hawkbit.repository.test.util.AbstractIntegrationTest; import org.junit.Before; import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -33,7 +33,7 @@ import ru.yandex.qatools.allure.annotations.Stories; @Stories("Test to generate the artifact download URL") @SpringApplicationConfiguration(classes = { AmqpTestConfiguration.class, org.eclipse.hawkbit.RepositoryApplicationConfiguration.class }) -public class PropertyBasedArtifactUrlHandlerTest extends AbstractIntegrationTestWithMongoDB { +public class PropertyBasedArtifactUrlHandlerTest extends AbstractIntegrationTest { private static final String HTTPS_LOCALHOST = "https://localhost/"; private static final String HTTP_LOCALHOST = "http://localhost/"; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractJpaIntegrationTestWithMongoDB.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractJpaIntegrationTestWithMongoDB.java index e2e755246..d2c2a7cfa 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractJpaIntegrationTestWithMongoDB.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractJpaIntegrationTestWithMongoDB.java @@ -12,12 +12,12 @@ import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; import org.eclipse.hawkbit.cache.TenantAwareCacheManager; -import org.eclipse.hawkbit.repository.test.util.AbstractIntegrationTestWithMongoDB; +import org.eclipse.hawkbit.repository.test.util.AbstractIntegrationTest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.SpringApplicationConfiguration; @SpringApplicationConfiguration(classes = { org.eclipse.hawkbit.RepositoryApplicationConfiguration.class }) -public abstract class AbstractJpaIntegrationTestWithMongoDB extends AbstractIntegrationTestWithMongoDB { +public abstract class AbstractJpaIntegrationTestWithMongoDB extends AbstractIntegrationTest { @PersistenceContext protected EntityManager entityManager; diff --git a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/AbstractIntegrationTest.java b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/AbstractIntegrationTest.java index b8c99b57a..8f3becc4c 100644 --- a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/AbstractIntegrationTest.java +++ b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/AbstractIntegrationTest.java @@ -49,6 +49,8 @@ import org.springframework.core.env.Environment; import org.springframework.data.auditing.AuditingHandler; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; +import org.springframework.data.mongodb.core.query.Query; +import org.springframework.data.mongodb.gridfs.GridFsOperations; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext.ClassMode; import org.springframework.test.context.ActiveProfiles; @@ -60,6 +62,8 @@ import org.springframework.test.web.servlet.setup.DefaultMockMvcBuilder; import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.web.context.WebApplicationContext; +import de.flapdoodle.embed.mongo.MongodExecutable; + @RunWith(SpringJUnit4ClassRunner.class) @WebAppConfiguration @ActiveProfiles({ "test" }) @@ -152,6 +156,12 @@ public abstract class AbstractIntegrationTest implements EnvironmentAware { @Autowired protected TestdataFactory testdataFactory; + @Autowired + protected GridFsOperations operations; + + @Autowired + protected MongodExecutable mongodExecutable; + @Rule public final WithSpringAuthorityRule securityRule = new WithSpringAuthorityRule(); @@ -190,6 +200,11 @@ public abstract class AbstractIntegrationTest implements EnvironmentAware { testRepositoryManagement.clearTestRepository(); } + @After + public void cleanCurrentCollection() { + operations.delete(new Query()); + } + protected DefaultMockMvcBuilder createMvcWebAppContext() { return MockMvcBuilders.webAppContextSetup(context) .addFilter(new DosFilter(100, 10, "127\\.0\\.0\\.1|\\[0:0:0:0:0:0:0:1\\]", "(^192\\.168\\.)", diff --git a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/AbstractIntegrationTestWithMongoDB.java b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/AbstractIntegrationTestWithMongoDB.java deleted file mode 100644 index 589cac381..000000000 --- a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/AbstractIntegrationTestWithMongoDB.java +++ /dev/null @@ -1,34 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.repository.test.util; - -import org.junit.After; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.mongodb.core.query.Query; -import org.springframework.data.mongodb.gridfs.GridFsOperations; - -import de.flapdoodle.embed.mongo.MongodExecutable; - -/** - * Test class that contains embedded MongoDB for the test. - */ -public abstract class AbstractIntegrationTestWithMongoDB extends AbstractIntegrationTest { - - @Autowired - protected GridFsOperations operations; - - @Autowired - protected MongodExecutable mongodExecutable; - - @After - public void cleanCurrentCollection() { - operations.delete(new Query()); - } - -} diff --git a/hawkbit-rest-core/src/test/java/org/eclipse/hawkbit/rest/AbstractRestIntegrationTestWithMongoDB.java b/hawkbit-rest-core/src/test/java/org/eclipse/hawkbit/rest/AbstractRestIntegrationTestWithMongoDB.java index 70d65e141..5974917ec 100644 --- a/hawkbit-rest-core/src/test/java/org/eclipse/hawkbit/rest/AbstractRestIntegrationTestWithMongoDB.java +++ b/hawkbit-rest-core/src/test/java/org/eclipse/hawkbit/rest/AbstractRestIntegrationTestWithMongoDB.java @@ -8,7 +8,7 @@ */ package org.eclipse.hawkbit.rest; -import org.eclipse.hawkbit.repository.test.util.AbstractIntegrationTestWithMongoDB; +import org.eclipse.hawkbit.repository.test.util.AbstractIntegrationTest; import org.eclipse.hawkbit.rest.configuration.RestConfiguration; import org.eclipse.hawkbit.rest.util.FilterHttpResponse; import org.springframework.beans.factory.annotation.Autowired; @@ -20,7 +20,7 @@ import org.springframework.test.web.servlet.setup.DefaultMockMvcBuilder; */ @SpringApplicationConfiguration(classes = { RestConfiguration.class, org.eclipse.hawkbit.RepositoryApplicationConfiguration.class }) -public abstract class AbstractRestIntegrationTestWithMongoDB extends AbstractIntegrationTestWithMongoDB { +public abstract class AbstractRestIntegrationTestWithMongoDB extends AbstractIntegrationTest { @Autowired private FilterHttpResponse filterHttpResponse; From 6dc288849939864ae0df51f7226d9e604715f023 Mon Sep 17 00:00:00 2001 From: kaizimmerm Date: Mon, 29 Aug 2016 14:12:56 +0200 Subject: [PATCH 22/24] Fixed merge mistake Signed-off-by: kaizimmerm --- .../RepositoryApplicationConfiguration.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/RepositoryApplicationConfiguration.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/RepositoryApplicationConfiguration.java index 8f0bc01d2..a62de9a06 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/RepositoryApplicationConfiguration.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/RepositoryApplicationConfiguration.java @@ -46,6 +46,7 @@ import org.eclipse.hawkbit.repository.jpa.aspects.ExceptionMappingAspectHandler; import org.eclipse.hawkbit.repository.jpa.configuration.MultiTenantJpaTransactionManager; import org.eclipse.hawkbit.repository.jpa.model.helper.AfterTransactionCommitExecutorHolder; import org.eclipse.hawkbit.repository.jpa.model.helper.CacheManagerHolder; +import org.eclipse.hawkbit.repository.jpa.model.helper.EntityInterceptorHolder; import org.eclipse.hawkbit.repository.jpa.model.helper.SecurityTokenGeneratorHolder; import org.eclipse.hawkbit.repository.jpa.model.helper.SystemManagementHolder; import org.eclipse.hawkbit.repository.jpa.model.helper.SystemSecurityContextHolder; @@ -72,6 +73,8 @@ import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.annotation.EnableTransactionManagement; import org.springframework.validation.beanvalidation.MethodValidationPostProcessor; +import com.google.common.eventbus.EventBus; + /** * General configuration for hawkBit's Repository. * @@ -86,6 +89,9 @@ import org.springframework.validation.beanvalidation.MethodValidationPostProcess @EnableScheduling @EntityScan("org.eclipse.hawkbit.repository.jpa.model") public class RepositoryApplicationConfiguration extends JpaBaseConfiguration { + @Autowired + private EventBus eventBus; + /** * @return the {@link SystemSecurityContext} singleton bean which make it * accessible in beans which cannot access the service directly, @@ -139,6 +145,14 @@ public class RepositoryApplicationConfiguration extends JpaBaseConfiguration { return SecurityTokenGeneratorHolder.getInstance(); } + /** + * @return the singleton instance of the {@link EntityInterceptorHolder} + */ + @Bean + public EntityInterceptorHolder entityInterceptorHolder() { + return EntityInterceptorHolder.getInstance(); + } + /** * @return the singleton instance of the {@link CacheManagerHolder} */ @@ -250,7 +264,9 @@ public class RepositoryApplicationConfiguration extends JpaBaseConfiguration { @Bean @ConditionalOnMissingBean public TenantStatsManagement tenantStatsManagement() { - return new JpaTenantStatsManagement(); + final TenantStatsManagement mgmt = new JpaTenantStatsManagement(); + eventBus.register(mgmt); + return mgmt; } /** From a1a7a6dc455b3d62a0d0f0fa558707f8fa7f4793 Mon Sep 17 00:00:00 2001 From: SirWayne Date: Mon, 29 Aug 2016 17:11:33 +0200 Subject: [PATCH 23/24] Adapt test to new json path Signed-off-by: SirWayne --- .../rest/resource/DdiCancelActionTest.java | 51 +-- .../ddi/rest/resource/DdiConfigDataTest.java | 8 +- .../rest/resource/DdiDeploymentBaseTest.java | 337 ++++++++++-------- .../rest/resource/DdiRootControllerTest.java | 16 +- .../MgmtDistributionSetResourceTest.java | 113 +++--- .../MgmtDistributionSetTypeResourceTest.java | 131 +++---- .../resource/MgmtRolloutResourceTest.java | 55 ++- .../MgmtSoftwareModuleResourceTest.java | 334 ++++++++--------- .../MgmtSoftwareModuleTypeResourceTest.java | 116 +++--- .../rest/resource/MgmtTargetResourceTest.java | 183 +++++----- pom.xml | 13 - 11 files changed, 684 insertions(+), 673 deletions(-) diff --git a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiCancelActionTest.java b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiCancelActionTest.java index 821c8b8ad..b476f5c8f 100644 --- a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiCancelActionTest.java +++ b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiCancelActionTest.java @@ -10,6 +10,7 @@ package org.eclipse.hawkbit.ddi.rest.resource; import static org.fest.assertions.api.Assertions.assertThat; import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.startsWith; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; @@ -74,15 +75,15 @@ public class DdiCancelActionTest extends AbstractRestIntegrationTest { mvc.perform(get("/{tenant}/controller/v1/4712/deploymentBase/" + updateAction.getId(), tenantAware.getCurrentTenant()).accept(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print()) .andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(jsonPath("$id", equalTo(String.valueOf(updateAction.getId())))) - .andExpect(jsonPath("$deployment.download", equalTo("forced"))) - .andExpect(jsonPath("$deployment.update", equalTo("forced"))) - .andExpect(jsonPath("$deployment.chunks[?(@.part==jvm)][0].version", - equalTo(ds.findFirstModuleByType(runtimeType).getVersion()))) - .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].version", - equalTo(ds.findFirstModuleByType(osType).getVersion()))) - .andExpect(jsonPath("$deployment.chunks[?(@.part==bApp)][0].version", - equalTo(ds.findFirstModuleByType(appType).getVersion()))); + .andExpect(jsonPath("$.id", equalTo(String.valueOf(updateAction.getId())))) + .andExpect(jsonPath("$.deployment.download", equalTo("forced"))) + .andExpect(jsonPath("$.deployment.update", equalTo("forced"))) + .andExpect(jsonPath("$.deployment.chunks[?(@.part==jvm)].version", + contains(ds.findFirstModuleByType(runtimeType).getVersion()))) + .andExpect(jsonPath("$.deployment.chunks[?(@.part==os)].version", + contains(ds.findFirstModuleByType(osType).getVersion()))) + .andExpect(jsonPath("$.deployment.chunks[?(@.part==bApp)].version", + contains(ds.findFirstModuleByType(appType).getVersion()))); // and finish it mvc.perform(post("/{tenant}/controller/v1/4712/deploymentBase/" + updateAction.getId() + "/feedback", @@ -118,8 +119,8 @@ public class DdiCancelActionTest extends AbstractRestIntegrationTest { mvc.perform(get("/{tenant}/controller/v1/4712", tenantAware.getCurrentTenant())) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaTypes.HAL_JSON)) - .andExpect(jsonPath("$config.polling.sleep", equalTo("00:01:00"))) - .andExpect(jsonPath("$_links.deploymentBase.href", + .andExpect(jsonPath("$.config.polling.sleep", equalTo("00:01:00"))) + .andExpect(jsonPath("$._links.deploymentBase.href", startsWith("http://localhost/" + tenantAware.getCurrentTenant() + "/controller/v1/4712/deploymentBase/" + updateAction.getId()))); Thread.sleep(1); // is required: otherwise processing the next line is @@ -150,8 +151,8 @@ public class DdiCancelActionTest extends AbstractRestIntegrationTest { mvc.perform(get("/{tenant}/controller/v1/4712", tenantAware.getCurrentTenant())) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaTypes.HAL_JSON)) - .andExpect(jsonPath("$config.polling.sleep", equalTo("00:01:00"))) - .andExpect(jsonPath("$_links.cancelAction.href", + .andExpect(jsonPath("$.config.polling.sleep", equalTo("00:01:00"))) + .andExpect(jsonPath("$._links.cancelAction.href", equalTo("http://localhost/" + tenantAware.getCurrentTenant() + "/controller/v1/4712/cancelAction/" + cancelAction.getId()))); Thread.sleep(1); // is required: otherwise processing the next line is @@ -170,8 +171,8 @@ public class DdiCancelActionTest extends AbstractRestIntegrationTest { .accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(jsonPath("$id", equalTo(String.valueOf(cancelAction.getId())))) - .andExpect(jsonPath("$cancelAction.stopId", equalTo(String.valueOf(updateAction.getId())))); + .andExpect(jsonPath("$.id", equalTo(String.valueOf(cancelAction.getId())))) + .andExpect(jsonPath("$.cancelAction.stopId", equalTo(String.valueOf(updateAction.getId())))); assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getLastTargetQuery()) .isLessThanOrEqualTo(System.currentTimeMillis()); assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getLastTargetQuery()) @@ -360,15 +361,15 @@ public class DdiCancelActionTest extends AbstractRestIntegrationTest { .accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(jsonPath("$id", equalTo(String.valueOf(cancelAction.getId())))) - .andExpect(jsonPath("$cancelAction.stopId", equalTo(String.valueOf(updateAction.getId())))); + .andExpect(jsonPath("$.id", equalTo(String.valueOf(cancelAction.getId())))) + .andExpect(jsonPath("$.cancelAction.stopId", equalTo(String.valueOf(updateAction.getId())))); assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(6); mvc.perform(get("/{tenant}/controller/v1/4712", tenantAware.getCurrentTenant())) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaTypes.HAL_JSON)) - .andExpect(jsonPath("$config.polling.sleep", equalTo("00:01:00"))) - .andExpect(jsonPath("$_links.cancelAction.href", + .andExpect(jsonPath("$.config.polling.sleep", equalTo("00:01:00"))) + .andExpect(jsonPath("$._links.cancelAction.href", equalTo("http://localhost/" + tenantAware.getCurrentTenant() + "/controller/v1/4712/cancelAction/" + cancelAction.getId()))); @@ -386,15 +387,15 @@ public class DdiCancelActionTest extends AbstractRestIntegrationTest { mvc.perform(get("/{tenant}/controller/v1/4712/cancelAction/" + cancelAction2.getId(), tenantAware.getCurrentTenant()).accept(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print()) .andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(jsonPath("$id", equalTo(String.valueOf(cancelAction2.getId())))) - .andExpect(jsonPath("$cancelAction.stopId", equalTo(String.valueOf(updateAction2.getId())))); + .andExpect(jsonPath("$.id", equalTo(String.valueOf(cancelAction2.getId())))) + .andExpect(jsonPath("$.cancelAction.stopId", equalTo(String.valueOf(updateAction2.getId())))); assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(8); mvc.perform(get("/{tenant}/controller/v1/4712", tenantAware.getCurrentTenant())) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaTypes.HAL_JSON)) - .andExpect(jsonPath("$config.polling.sleep", equalTo("00:01:00"))) - .andExpect(jsonPath("$_links.cancelAction.href", + .andExpect(jsonPath("$.config.polling.sleep", equalTo("00:01:00"))) + .andExpect(jsonPath("$._links.cancelAction.href", equalTo("http://localhost/" + tenantAware.getCurrentTenant() + "/controller/v1/4712/cancelAction/" + cancelAction2.getId()))); @@ -426,8 +427,8 @@ public class DdiCancelActionTest extends AbstractRestIntegrationTest { mvc.perform(get("/{tenant}/controller/v1/4712/cancelAction/" + cancelAction3.getId(), tenantAware.getCurrentTenant()).accept(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print()) .andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(jsonPath("$id", equalTo(String.valueOf(cancelAction3.getId())))) - .andExpect(jsonPath("$cancelAction.stopId", equalTo(String.valueOf(updateAction3.getId())))); + .andExpect(jsonPath("$.id", equalTo(String.valueOf(cancelAction3.getId())))) + .andExpect(jsonPath("$.cancelAction.stopId", equalTo(String.valueOf(updateAction3.getId())))); assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(12); // now lets return feedback for the third cancelation diff --git a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiConfigDataTest.java b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiConfigDataTest.java index 395e2284c..aa26c3931 100644 --- a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiConfigDataTest.java +++ b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiConfigDataTest.java @@ -53,8 +53,8 @@ public class DdiConfigDataTest extends AbstractRestIntegrationTest { mvc.perform(get("/{tenant}/controller/v1/4712", tenantAware.getCurrentTenant())) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaTypes.HAL_JSON)) - .andExpect(jsonPath("$config.polling.sleep", equalTo("00:01:00"))) - .andExpect(jsonPath("$_links.configData.href", equalTo( + .andExpect(jsonPath("$.config.polling.sleep", equalTo("00:01:00"))) + .andExpect(jsonPath("$._links.configData.href", equalTo( "http://localhost/" + tenantAware.getCurrentTenant() + "/controller/v1/4712/configData"))); Thread.sleep(1); // is required: otherwise processing the next line is // often too fast and @@ -76,8 +76,8 @@ public class DdiConfigDataTest extends AbstractRestIntegrationTest { mvc.perform(get("/{tenant}/controller/v1/4712", tenantAware.getCurrentTenant())) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaTypes.HAL_JSON)) - .andExpect(jsonPath("$config.polling.sleep", equalTo("00:01:00"))) - .andExpect(jsonPath("$_links.configData.href").doesNotExist()); + .andExpect(jsonPath("$.config.polling.sleep", equalTo("00:01:00"))) + .andExpect(jsonPath("$._links.configData.href").doesNotExist()); } @Test diff --git a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiDeploymentBaseTest.java b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiDeploymentBaseTest.java index 584c774d5..f9625dff7 100644 --- a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiDeploymentBaseTest.java +++ b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiDeploymentBaseTest.java @@ -10,6 +10,7 @@ package org.eclipse.hawkbit.ddi.rest.resource; import static org.fest.assertions.api.Assertions.assertThat; import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.startsWith; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; @@ -91,9 +92,9 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD mvc.perform(get("/{tenant}/controller/v1/{targetNotExist}/softwaremodules/{softwareModuleId}/artifacts", tenantAware.getCurrentTenant(), target.getName(), softwareModuleId)).andDo(MockMvcResultPrinter.print()) .andExpect(status().isOk()).andExpect(jsonPath("$", hasSize(3))) - .andExpect(jsonPath("$[?(@.filename==filename0)]", hasSize(1))) - .andExpect(jsonPath("$[?(@.filename==filename1)]", hasSize(1))) - .andExpect(jsonPath("$[?(@.filename==filename2)]", hasSize(1))); + .andExpect(jsonPath("$.[?(@.filename==filename0)]", hasSize(1))) + .andExpect(jsonPath("$.[?(@.filename==filename1)]", hasSize(1))) + .andExpect(jsonPath("$.[?(@.filename==filename2)]", hasSize(1))); } @@ -136,8 +137,8 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD mvc.perform(get("/{tenant}/controller/v1/4712", tenantAware.getCurrentTenant())) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaTypes.HAL_JSON)) - .andExpect(jsonPath("$config.polling.sleep", equalTo("00:01:00"))) - .andExpect(jsonPath("$_links.deploymentBase.href", startsWith("http://localhost/" + .andExpect(jsonPath("$.config.polling.sleep", equalTo("00:01:00"))) + .andExpect(jsonPath("$._links.deploymentBase.href", startsWith("http://localhost/" + tenantAware.getCurrentTenant() + "/controller/v1/4712/deploymentBase/" + uaction.getId()))); assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getLastTargetQuery()) .isGreaterThanOrEqualTo(current); @@ -155,74 +156,82 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD .accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(jsonPath("$id", equalTo(String.valueOf(action.getId())))) - .andExpect(jsonPath("$deployment.download", equalTo("forced"))) - .andExpect(jsonPath("$deployment.update", equalTo("forced"))) - .andExpect(jsonPath("$deployment.chunks[?(@.part==jvm)][0].name", - equalTo(ds.findFirstModuleByType(runtimeType).getName()))) - .andExpect(jsonPath("$deployment.chunks[?(@.part==jvm)][0].version", - equalTo(ds.findFirstModuleByType(runtimeType).getVersion()))) - .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].name", - equalTo(ds.findFirstModuleByType(osType).getName()))) - .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].version", - equalTo(ds.findFirstModuleByType(osType).getVersion()))) - .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[0].size", equalTo(5 * 1024))) - .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[0].filename", equalTo("test1"))) - .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[0].hashes.md5", - equalTo(artifact.getMd5Hash()))) + .andExpect(jsonPath("$.id", equalTo(String.valueOf(action.getId())))) + .andExpect(jsonPath("$.deployment.download", equalTo("forced"))) + .andExpect(jsonPath("$.deployment.update", equalTo("forced"))) + .andExpect(jsonPath("$.deployment.chunks[?(@.part==jvm)].name", + contains(ds.findFirstModuleByType(runtimeType).getName()))) + .andExpect(jsonPath("$.deployment.chunks[?(@.part==jvm)].version", + contains(ds.findFirstModuleByType(runtimeType).getVersion()))) + .andExpect(jsonPath("$.deployment.chunks[?(@.part==os)].name", + contains(ds.findFirstModuleByType(osType).getName()))) + .andExpect(jsonPath("$.deployment.chunks[?(@.part==os)].version", + contains(ds.findFirstModuleByType(osType).getVersion()))) + .andExpect(jsonPath("$.deployment.chunks[?(@.part==os)].artifacts[0].size", contains(5 * 1024))) + .andExpect(jsonPath("$.deployment.chunks[?(@.part==os)].artifacts[0].filename", contains("test1"))) + .andExpect(jsonPath("$.deployment.chunks[?(@.part==os)].artifacts[0].hashes.md5", + contains(artifact.getMd5Hash()))) .andExpect( - jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[0].hashes.sha1", - equalTo(artifact.getSha1Hash()))) - .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[0]._links.download.href", - equalTo(HTTPS_LOCALHOST + tenantAware.getCurrentTenant() + jsonPath("$.deployment.chunks[?(@.part==os)].artifacts[0].hashes.sha1", + contains(artifact.getSha1Hash()))) + .andExpect(jsonPath("$.deployment.chunks[?(@.part==os)].artifacts[0]._links.download.href", + contains(HTTPS_LOCALHOST + tenantAware.getCurrentTenant() + "/controller/v1/4712/softwaremodules/" + findDistributionSetByAction.findFirstModuleByType(osType).getId() + "/artifacts/test1"))) - .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[0]._links.md5sum.href", - equalTo(HTTPS_LOCALHOST + tenantAware.getCurrentTenant() + .andExpect(jsonPath("$.deployment.chunks[?(@.part==os)].artifacts[0]._links.md5sum.href", + contains(HTTPS_LOCALHOST + tenantAware.getCurrentTenant() + "/controller/v1/4712/softwaremodules/" + findDistributionSetByAction.findFirstModuleByType(osType).getId() + "/artifacts/test1.MD5SUM"))) - .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[0]._links.download-http.href", - equalTo(HTTP_LOCALHOST + tenantAware.getCurrentTenant() + "/controller/v1/4712/softwaremodules/" - + findDistributionSetByAction.findFirstModuleByType(osType).getId() - + "/artifacts/test1"))) - .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[0]._links.md5sum-http.href", - equalTo(HTTP_LOCALHOST + tenantAware.getCurrentTenant() + "/controller/v1/4712/softwaremodules/" - + findDistributionSetByAction.findFirstModuleByType(osType).getId() - + "/artifacts/test1.MD5SUM"))) - - .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[1].size", equalTo(5 * 1024))) - .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[1].filename", - equalTo("test1.signature"))) - .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[1].hashes.md5", - equalTo(artifactSignature.getMd5Hash()))) .andExpect( - jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[1].hashes.sha1", - equalTo(artifactSignature.getSha1Hash()))) - .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[1]._links.download.href", - equalTo(HTTPS_LOCALHOST + tenantAware.getCurrentTenant() + jsonPath("$.deployment.chunks[?(@.part==os)].artifacts[0]._links.download-http.href", + contains(HTTP_LOCALHOST + tenantAware.getCurrentTenant() + + "/controller/v1/4712/softwaremodules/" + + findDistributionSetByAction.findFirstModuleByType(osType).getId() + + "/artifacts/test1"))) + .andExpect( + jsonPath("$.deployment.chunks[?(@.part==os)].artifacts[0]._links.md5sum-http.href", + contains(HTTP_LOCALHOST + tenantAware.getCurrentTenant() + + "/controller/v1/4712/softwaremodules/" + + findDistributionSetByAction.findFirstModuleByType(osType).getId() + + "/artifacts/test1.MD5SUM"))) + + .andExpect(jsonPath("$.deployment.chunks[?(@.part==os)].artifacts[1].size", contains(5 * 1024))) + .andExpect(jsonPath("$.deployment.chunks[?(@.part==os)].artifacts[1].filename", + contains("test1.signature"))) + .andExpect(jsonPath("$.deployment.chunks[?(@.part==os)].artifacts[1].hashes.md5", + contains(artifactSignature.getMd5Hash()))) + .andExpect( + jsonPath("$.deployment.chunks[?(@.part==os)].artifacts[1].hashes.sha1", + contains(artifactSignature.getSha1Hash()))) + .andExpect(jsonPath("$.deployment.chunks[?(@.part==os)].artifacts[1]._links.download.href", + contains(HTTPS_LOCALHOST + tenantAware.getCurrentTenant() + "/controller/v1/4712/softwaremodules/" + findDistributionSetByAction.findFirstModuleByType(osType).getId() + "/artifacts/test1.signature"))) - .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[1]._links.md5sum.href", - equalTo(HTTPS_LOCALHOST + tenantAware.getCurrentTenant() + .andExpect(jsonPath("$.deployment.chunks[?(@.part==os)].artifacts[1]._links.md5sum.href", + contains(HTTPS_LOCALHOST + tenantAware.getCurrentTenant() + "/controller/v1/4712/softwaremodules/" + findDistributionSetByAction.findFirstModuleByType(osType).getId() + "/artifacts/test1.signature.MD5SUM"))) - .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[1]._links.download-http.href", - equalTo(HTTP_LOCALHOST + tenantAware.getCurrentTenant() + "/controller/v1/4712/softwaremodules/" - + findDistributionSetByAction.findFirstModuleByType(osType).getId() - + "/artifacts/test1.signature"))) - .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[1]._links.md5sum-http.href", - equalTo(HTTP_LOCALHOST + tenantAware.getCurrentTenant() + "/controller/v1/4712/softwaremodules/" - + findDistributionSetByAction.findFirstModuleByType(osType).getId() - + "/artifacts/test1.signature.MD5SUM"))) - .andExpect(jsonPath("$deployment.chunks[?(@.part==bApp)][0].version", - equalTo(ds.findFirstModuleByType(appType).getVersion()))) - .andExpect(jsonPath("$deployment.chunks[?(@.part==bApp)][0].name", - equalTo(ds.findFirstModuleByType(appType).getName()))); + .andExpect( + jsonPath("$.deployment.chunks[?(@.part==os)].artifacts[1]._links.download-http.href", + contains(HTTP_LOCALHOST + tenantAware.getCurrentTenant() + + "/controller/v1/4712/softwaremodules/" + + findDistributionSetByAction.findFirstModuleByType(osType).getId() + + "/artifacts/test1.signature"))) + .andExpect( + jsonPath("$.deployment.chunks[?(@.part==os)].artifacts[1]._links.md5sum-http.href", + contains(HTTP_LOCALHOST + tenantAware.getCurrentTenant() + + "/controller/v1/4712/softwaremodules/" + + findDistributionSetByAction.findFirstModuleByType(osType).getId() + + "/artifacts/test1.signature.MD5SUM"))) + .andExpect(jsonPath("$.deployment.chunks[?(@.part==bApp)].version", + contains(ds.findFirstModuleByType(appType).getVersion()))) + .andExpect(jsonPath("$.deployment.chunks[?(@.part==bApp)].name", + contains(ds.findFirstModuleByType(appType).getName()))); assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getLastTargetQuery()) .isGreaterThanOrEqualTo(current); @@ -313,8 +322,8 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD mvc.perform(get("/{tenant}/controller/v1/4712", tenantAware.getCurrentTenant())) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaTypes.HAL_JSON)) - .andExpect(jsonPath("$config.polling.sleep", equalTo("00:01:00"))) - .andExpect(jsonPath("$_links.deploymentBase.href", startsWith("http://localhost/" + .andExpect(jsonPath("$.config.polling.sleep", equalTo("00:01:00"))) + .andExpect(jsonPath("$._links.deploymentBase.href", startsWith("http://localhost/" + tenantAware.getCurrentTenant() + "/controller/v1/4712/deploymentBase/" + uaction.getId()))); assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getLastTargetQuery()) .isGreaterThanOrEqualTo(current); @@ -332,64 +341,68 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD .accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(jsonPath("$id", equalTo(String.valueOf(action.getId())))) - .andExpect(jsonPath("$deployment.download", equalTo("attempt"))) - .andExpect(jsonPath("$deployment.update", equalTo("attempt"))) - .andExpect(jsonPath("$deployment.chunks[?(@.part==jvm)][0].name", - equalTo(ds.findFirstModuleByType(runtimeType).getName()))) - .andExpect(jsonPath("$deployment.chunks[?(@.part==jvm)][0].version", - equalTo(ds.findFirstModuleByType(runtimeType).getVersion()))) - .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].name", - equalTo(ds.findFirstModuleByType(osType).getName()))) - .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].version", - equalTo(ds.findFirstModuleByType(osType).getVersion()))) - .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[0].size", equalTo(5 * 1024))) - .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[0].filename", equalTo("test1"))) - .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[0].hashes.md5", - equalTo(artifact.getMd5Hash()))) + .andExpect(jsonPath("$.id", equalTo(String.valueOf(action.getId())))) + .andExpect(jsonPath("$.deployment.download", equalTo("attempt"))) + .andExpect(jsonPath("$.deployment.update", equalTo("attempt"))) + .andExpect(jsonPath("$.deployment.chunks[?(@.part==jvm)].name", + contains(ds.findFirstModuleByType(runtimeType).getName()))) + .andExpect(jsonPath("$.deployment.chunks[?(@.part==jvm)].version", + contains(ds.findFirstModuleByType(runtimeType).getVersion()))) + .andExpect(jsonPath("$.deployment.chunks[?(@.part==os)].name", + contains(ds.findFirstModuleByType(osType).getName()))) + .andExpect(jsonPath("$.deployment.chunks[?(@.part==os)].version", + contains(ds.findFirstModuleByType(osType).getVersion()))) + .andExpect(jsonPath("$.deployment.chunks[?(@.part==os)].artifacts[0].size", contains(5 * 1024))) + .andExpect(jsonPath("$.deployment.chunks[?(@.part==os)].artifacts[0].filename", contains("test1"))) + .andExpect(jsonPath("$.deployment.chunks[?(@.part==os)].artifacts[0].hashes.md5", + contains(artifact.getMd5Hash()))) .andExpect( - jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[0].hashes.sha1", - equalTo(artifact.getSha1Hash()))) - .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[0]._links.download.href", - equalTo(HTTPS_LOCALHOST + tenantAware.getCurrentTenant() + jsonPath("$.deployment.chunks[?(@.part==os)].artifacts[0].hashes.sha1", + contains(artifact.getSha1Hash()))) + .andExpect(jsonPath("$.deployment.chunks[?(@.part==os)].artifacts[0]._links.download.href", + contains(HTTPS_LOCALHOST + tenantAware.getCurrentTenant() + "/controller/v1/4712/softwaremodules/" + findDistributionSetByAction.findFirstModuleByType(osType).getId() + "/artifacts/test1"))) - .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[0]._links.md5sum.href", - equalTo(HTTPS_LOCALHOST + tenantAware.getCurrentTenant() + .andExpect(jsonPath("$.deployment.chunks[?(@.part==os)].artifacts[0]._links.md5sum.href", + contains(HTTPS_LOCALHOST + tenantAware.getCurrentTenant() + "/controller/v1/4712/softwaremodules/" + findDistributionSetByAction.findFirstModuleByType(osType).getId() + "/artifacts/test1.MD5SUM"))) - .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[1].size", equalTo(5 * 1024))) - .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[1].filename", - equalTo("test1.signature"))) - .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[1].hashes.md5", - equalTo(artifactSignature.getMd5Hash()))) + .andExpect(jsonPath("$.deployment.chunks[?(@.part==os)].artifacts[1].size", contains(5 * 1024))) + .andExpect(jsonPath("$.deployment.chunks[?(@.part==os)].artifacts[1].filename", + contains("test1.signature"))) + .andExpect(jsonPath("$.deployment.chunks[?(@.part==os)].artifacts[1].hashes.md5", + contains(artifactSignature.getMd5Hash()))) .andExpect( - jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[1].hashes.sha1", - equalTo(artifactSignature.getSha1Hash()))) - .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[1]._links.download.href", - equalTo(HTTPS_LOCALHOST + tenantAware.getCurrentTenant() + jsonPath("$.deployment.chunks[?(@.part==os)].artifacts[1].hashes.sha1", + contains(artifactSignature.getSha1Hash()))) + .andExpect(jsonPath("$.deployment.chunks[?(@.part==os)].artifacts[1]._links.download.href", + contains(HTTPS_LOCALHOST + tenantAware.getCurrentTenant() + "/controller/v1/4712/softwaremodules/" + findDistributionSetByAction.findFirstModuleByType(osType).getId() + "/artifacts/test1.signature"))) - .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[1]._links.md5sum.href", - equalTo(HTTPS_LOCALHOST + tenantAware.getCurrentTenant() + .andExpect(jsonPath("$.deployment.chunks[?(@.part==os)].artifacts[1]._links.md5sum.href", + contains(HTTPS_LOCALHOST + tenantAware.getCurrentTenant() + "/controller/v1/4712/softwaremodules/" + findDistributionSetByAction.findFirstModuleByType(osType).getId() + "/artifacts/test1.signature.MD5SUM"))) - .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[1]._links.download-http.href", - equalTo(HTTP_LOCALHOST + tenantAware.getCurrentTenant() + "/controller/v1/4712/softwaremodules/" - + findDistributionSetByAction.findFirstModuleByType(osType).getId() - + "/artifacts/test1.signature"))) - .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[1]._links.md5sum-http.href", - equalTo(HTTP_LOCALHOST + tenantAware.getCurrentTenant() + "/controller/v1/4712/softwaremodules/" - + findDistributionSetByAction.findFirstModuleByType(osType).getId() - + "/artifacts/test1.signature.MD5SUM"))) - .andExpect(jsonPath("$deployment.chunks[?(@.part==bApp)][0].version", - equalTo(ds.findFirstModuleByType(appType).getVersion()))) - .andExpect(jsonPath("$deployment.chunks[?(@.part==bApp)][0].name", - equalTo(ds.findFirstModuleByType(appType).getName()))); + .andExpect( + jsonPath("$.deployment.chunks[?(@.part==os)].artifacts[1]._links.download-http.href", + contains(HTTP_LOCALHOST + tenantAware.getCurrentTenant() + + "/controller/v1/4712/softwaremodules/" + + findDistributionSetByAction.findFirstModuleByType(osType).getId() + + "/artifacts/test1.signature"))) + .andExpect( + jsonPath("$.deployment.chunks[?(@.part==os)].artifacts[1]._links.md5sum-http.href", + contains(HTTP_LOCALHOST + tenantAware.getCurrentTenant() + + "/controller/v1/4712/softwaremodules/" + + findDistributionSetByAction.findFirstModuleByType(osType).getId() + + "/artifacts/test1.signature.MD5SUM"))) + .andExpect(jsonPath("$.deployment.chunks[?(@.part==bApp)].version", + contains(ds.findFirstModuleByType(appType).getVersion()))) + .andExpect(jsonPath("$.deployment.chunks[?(@.part==bApp)].name", + contains(ds.findFirstModuleByType(appType).getName()))); assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getLastTargetQuery()) .isGreaterThanOrEqualTo(current); @@ -441,8 +454,8 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD mvc.perform(get("/{tenant}/controller/v1/4712", tenantAware.getCurrentTenant())) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaTypes.HAL_JSON)) - .andExpect(jsonPath("$config.polling.sleep", equalTo("00:01:00"))) - .andExpect(jsonPath("$_links.deploymentBase.href", startsWith("http://localhost/" + .andExpect(jsonPath("$.config.polling.sleep", equalTo("00:01:00"))) + .andExpect(jsonPath("$._links.deploymentBase.href", startsWith("http://localhost/" + tenantAware.getCurrentTenant() + "/controller/v1/4712/deploymentBase/" + uaction.getId()))); assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getLastTargetQuery()) .isGreaterThanOrEqualTo(current); @@ -458,74 +471,82 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD mvc.perform(get("/{tenant}/controller/v1/4712/deploymentBase/{actionId}", tenantAware.getCurrentTenant(), uaction.getId()).accept(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print()) .andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(jsonPath("$id", equalTo(String.valueOf(action.getId())))) - .andExpect(jsonPath("$deployment.download", equalTo("forced"))) - .andExpect(jsonPath("$deployment.update", equalTo("forced"))) - .andExpect(jsonPath("$deployment.chunks[?(@.part==jvm)][0].name", - equalTo(ds.findFirstModuleByType(runtimeType).getName()))) - .andExpect(jsonPath("$deployment.chunks[?(@.part==jvm)][0].version", - equalTo(ds.findFirstModuleByType(runtimeType).getVersion()))) - .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].name", - equalTo(ds.findFirstModuleByType(osType).getName()))) - .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].version", - equalTo(ds.findFirstModuleByType(osType).getVersion()))) - .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[0].size", equalTo(5 * 1024))) - .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[0].filename", equalTo("test1"))) - .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[0].hashes.md5", - equalTo(artifact.getMd5Hash()))) - .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[0].hashes.sha1", - equalTo(artifact.getSha1Hash()))) + .andExpect(jsonPath("$.id", equalTo(String.valueOf(action.getId())))) + .andExpect(jsonPath("$.deployment.download", equalTo("forced"))) + .andExpect(jsonPath("$.deployment.update", equalTo("forced"))) + .andExpect(jsonPath("$.deployment.chunks[?(@.part==jvm)].name", + contains(ds.findFirstModuleByType(runtimeType).getName()))) + .andExpect(jsonPath("$.deployment.chunks[?(@.part==jvm)].version", + contains(ds.findFirstModuleByType(runtimeType).getVersion()))) + .andExpect(jsonPath("$.deployment.chunks[?(@.part==os)].name", + contains(ds.findFirstModuleByType(osType).getName()))) + .andExpect(jsonPath("$.deployment.chunks[?(@.part==os)].version", + contains(ds.findFirstModuleByType(osType).getVersion()))) + .andExpect(jsonPath("$.deployment.chunks[?(@.part==os)].artifacts[0].size", contains(5 * 1024))) + .andExpect(jsonPath("$.deployment.chunks[?(@.part==os)].artifacts[0].filename", contains("test1"))) + .andExpect(jsonPath("$.deployment.chunks[?(@.part==os)].artifacts[0].hashes.md5", + contains(artifact.getMd5Hash()))) + .andExpect(jsonPath("$.deployment.chunks[?(@.part==os)].artifacts[0].hashes.sha1", + contains(artifact.getSha1Hash()))) - .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[0]._links.download.href", - equalTo(HTTPS_LOCALHOST + tenantAware.getCurrentTenant() + .andExpect(jsonPath("$.deployment.chunks[?(@.part==os)].artifacts[0]._links.download.href", + contains(HTTPS_LOCALHOST + tenantAware.getCurrentTenant() + "/controller/v1/4712/softwaremodules/" + findDistributionSetByAction.findFirstModuleByType(osType).getId() + "/artifacts/test1"))) - .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[0]._links.md5sum.href", - equalTo(HTTPS_LOCALHOST + tenantAware.getCurrentTenant() + .andExpect(jsonPath("$.deployment.chunks[?(@.part==os)].artifacts[0]._links.md5sum.href", + contains(HTTPS_LOCALHOST + tenantAware.getCurrentTenant() + "/controller/v1/4712/softwaremodules/" + findDistributionSetByAction.findFirstModuleByType(osType).getId() + "/artifacts/test1.MD5SUM"))) - .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[0]._links.download-http.href", - equalTo(HTTP_LOCALHOST + tenantAware.getCurrentTenant() + "/controller/v1/4712/softwaremodules/" - + findDistributionSetByAction.findFirstModuleByType(osType).getId() - + "/artifacts/test1"))) - .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[0]._links.md5sum-http.href", - equalTo(HTTP_LOCALHOST + tenantAware.getCurrentTenant() + "/controller/v1/4712/softwaremodules/" - + findDistributionSetByAction.findFirstModuleByType(osType).getId() - + "/artifacts/test1.MD5SUM"))) - .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[1].size", equalTo(5 * 1024))) - .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[1].filename", - equalTo("test1.signature"))) - .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[1].hashes.md5", - equalTo(artifactSignature.getMd5Hash()))) .andExpect( - jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[1].hashes.sha1", - equalTo(artifactSignature.getSha1Hash()))) - .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[1]._links.download.href", - equalTo(HTTPS_LOCALHOST + tenantAware.getCurrentTenant() + jsonPath("$.deployment.chunks[?(@.part==os)].artifacts[0]._links.download-http.href", + contains(HTTP_LOCALHOST + tenantAware.getCurrentTenant() + + "/controller/v1/4712/softwaremodules/" + + findDistributionSetByAction.findFirstModuleByType(osType).getId() + + "/artifacts/test1"))) + .andExpect( + jsonPath("$.deployment.chunks[?(@.part==os)].artifacts[0]._links.md5sum-http.href", + contains(HTTP_LOCALHOST + tenantAware.getCurrentTenant() + + "/controller/v1/4712/softwaremodules/" + + findDistributionSetByAction.findFirstModuleByType(osType).getId() + + "/artifacts/test1.MD5SUM"))) + .andExpect(jsonPath("$.deployment.chunks[?(@.part==os)].artifacts[1].size", contains(5 * 1024))) + .andExpect(jsonPath("$.deployment.chunks[?(@.part==os)].artifacts[1].filename", + contains("test1.signature"))) + .andExpect(jsonPath("$.deployment.chunks[?(@.part==os)].artifacts[1].hashes.md5", + contains(artifactSignature.getMd5Hash()))) + .andExpect( + jsonPath("$.deployment.chunks[?(@.part==os)].artifacts[1].hashes.sha1", + contains(artifactSignature.getSha1Hash()))) + .andExpect(jsonPath("$.deployment.chunks[?(@.part==os)].artifacts[1]._links.download.href", + contains(HTTPS_LOCALHOST + tenantAware.getCurrentTenant() + "/controller/v1/4712/softwaremodules/" + findDistributionSetByAction.findFirstModuleByType(osType).getId() + "/artifacts/test1.signature"))) - .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[1]._links.md5sum.href", - equalTo(HTTPS_LOCALHOST + tenantAware.getCurrentTenant() + .andExpect(jsonPath("$.deployment.chunks[?(@.part==os)].artifacts[1]._links.md5sum.href", + contains(HTTPS_LOCALHOST + tenantAware.getCurrentTenant() + "/controller/v1/4712/softwaremodules/" + findDistributionSetByAction.findFirstModuleByType(osType).getId() + "/artifacts/test1.signature.MD5SUM"))) - .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[1]._links.download-http.href", - equalTo(HTTP_LOCALHOST + tenantAware.getCurrentTenant() + "/controller/v1/4712/softwaremodules/" - + findDistributionSetByAction.findFirstModuleByType(osType).getId() - + "/artifacts/test1.signature"))) - .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[1]._links.md5sum-http.href", - equalTo(HTTP_LOCALHOST + tenantAware.getCurrentTenant() + "/controller/v1/4712/softwaremodules/" - + findDistributionSetByAction.findFirstModuleByType(osType).getId() - + "/artifacts/test1.signature.MD5SUM"))) + .andExpect( + jsonPath("$.deployment.chunks[?(@.part==os)].artifacts[1]._links.download-http.href", + contains(HTTP_LOCALHOST + tenantAware.getCurrentTenant() + + "/controller/v1/4712/softwaremodules/" + + findDistributionSetByAction.findFirstModuleByType(osType).getId() + + "/artifacts/test1.signature"))) + .andExpect( + jsonPath("$.deployment.chunks[?(@.part==os)].artifacts[1]._links.md5sum-http.href", + contains(HTTP_LOCALHOST + tenantAware.getCurrentTenant() + + "/controller/v1/4712/softwaremodules/" + + findDistributionSetByAction.findFirstModuleByType(osType).getId() + + "/artifacts/test1.signature.MD5SUM"))) - .andExpect(jsonPath("$deployment.chunks[?(@.part==bApp)][0].version", - equalTo(ds.findFirstModuleByType(appType).getVersion()))) - .andExpect(jsonPath("$deployment.chunks[?(@.part==bApp)][0].name", - equalTo(ds.findFirstModuleByType(appType).getName()))); + .andExpect(jsonPath("$.deployment.chunks[?(@.part==bApp)].version", + contains(ds.findFirstModuleByType(appType).getVersion()))) + .andExpect(jsonPath("$.deployment.chunks[?(@.part==bApp)].name", + contains(ds.findFirstModuleByType(appType).getName()))); assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getLastTargetQuery()) .isGreaterThanOrEqualTo(current); diff --git a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootControllerTest.java b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootControllerTest.java index ba5e3d2f6..7aad25600 100644 --- a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootControllerTest.java +++ b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootControllerTest.java @@ -123,7 +123,7 @@ public class DdiRootControllerTest extends AbstractRestIntegrationTestWithMongoD final long current = System.currentTimeMillis(); mvc.perform(get("/default-tenant/controller/v1/4711")).andDo(MockMvcResultPrinter.print()) .andExpect(status().isOk()).andExpect(content().contentType(MediaTypes.HAL_JSON)) - .andExpect(jsonPath("$config.polling.sleep", equalTo("00:01:00"))); + .andExpect(jsonPath("$.config.polling.sleep", equalTo("00:01:00"))); assertThat(targetManagement.findTargetByControllerID("4711").getTargetInfo().getLastTargetQuery()) .isGreaterThanOrEqualTo(current); @@ -155,7 +155,7 @@ public class DdiRootControllerTest extends AbstractRestIntegrationTestWithMongoD mvc.perform(get("/{tenant}/controller/v1/4711", tenantAware.getCurrentTenant())) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaTypes.HAL_JSON)) - .andExpect(jsonPath("$config.polling.sleep", equalTo("00:02:00"))); + .andExpect(jsonPath("$.config.polling.sleep", equalTo("00:02:00"))); return null; }); } @@ -166,7 +166,7 @@ public class DdiRootControllerTest extends AbstractRestIntegrationTestWithMongoD final String etag = mvc.perform(get("/{tenant}/controller/v1/4711", tenantAware.getCurrentTenant())) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaTypes.HAL_JSON)) - .andExpect(jsonPath("$config.polling.sleep", equalTo("00:01:00"))).andReturn().getResponse() + .andExpect(jsonPath("$.config.polling.sleep", equalTo("00:01:00"))).andReturn().getResponse() .getHeader("ETag"); mvc.perform(get("/{tenant}/controller/v1/4711", tenantAware.getCurrentTenant()).header("If-None-Match", etag)) @@ -183,8 +183,8 @@ public class DdiRootControllerTest extends AbstractRestIntegrationTestWithMongoD .header("If-None-Match", etag).accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(jsonPath("$config.polling.sleep", equalTo("00:01:00"))) - .andExpect(jsonPath("$_links.deploymentBase.href", + .andExpect(jsonPath("$.config.polling.sleep", equalTo("00:01:00"))) + .andExpect(jsonPath("$._links.deploymentBase.href", startsWith("http://localhost/" + tenantAware.getCurrentTenant() + "/controller/v1/4711/deploymentBase/" + updateAction.getId()))) .andReturn().getResponse().getHeader("ETag"); @@ -216,8 +216,8 @@ public class DdiRootControllerTest extends AbstractRestIntegrationTestWithMongoD .header("If-None-Match", etagWithFirstUpdate).accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(jsonPath("$config.polling.sleep", equalTo("00:01:00"))) - .andExpect(jsonPath("$_links.deploymentBase.href", + .andExpect(jsonPath("$.config.polling.sleep", equalTo("00:01:00"))) + .andExpect(jsonPath("$._links.deploymentBase.href", startsWith("http://localhost/" + tenantAware.getCurrentTenant() + "/controller/v1/4711/deploymentBase/" + updateAction2.getId()))) .andReturn().getResponse().getHeader("ETag"); @@ -237,7 +237,7 @@ public class DdiRootControllerTest extends AbstractRestIntegrationTestWithMongoD mvc.perform(get("/{tenant}/controller/v1/4711", tenantAware.getCurrentTenant())) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaTypes.HAL_JSON)) - .andExpect(jsonPath("$config.polling.sleep", equalTo("00:01:00"))); + .andExpect(jsonPath("$.config.polling.sleep", equalTo("00:01:00"))); assertThat(targetManagement.findTargetByControllerID("4711").getTargetInfo().getLastTargetQuery()) .isLessThanOrEqualTo(System.currentTimeMillis()); assertThat(targetManagement.findTargetByControllerID("4711").getTargetInfo().getLastTargetQuery()) diff --git a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResourceTest.java b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResourceTest.java index 556454f93..8aa035594 100644 --- a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResourceTest.java +++ b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResourceTest.java @@ -10,6 +10,7 @@ package org.eclipse.hawkbit.mgmt.rest.resource; import static org.fest.assertions.api.Assertions.assertThat; import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.hasSize; import static org.junit.Assert.fail; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; @@ -29,12 +30,12 @@ import java.util.Set; import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; import org.eclipse.hawkbit.repository.model.Action.Status; -import org.eclipse.hawkbit.repository.test.util.TestdataFactory; -import org.eclipse.hawkbit.repository.test.util.WithUser; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetMetadata; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.Target; +import org.eclipse.hawkbit.repository.test.util.TestdataFactory; +import org.eclipse.hawkbit.repository.test.util.WithUser; import org.eclipse.hawkbit.rest.AbstractRestIntegrationTest; import org.eclipse.hawkbit.rest.util.JsonBuilder; import org.eclipse.hawkbit.rest.util.MockMvcResultPrinter; @@ -362,25 +363,25 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest mvc.perform(get("/rest/v1/distributionsets").accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(jsonPath("$content.[0]._links.self.href", + .andExpect(jsonPath("$.content.[0]._links.self.href", equalTo("http://localhost/rest/v1/distributionsets/" + set.getId()))) - .andExpect(jsonPath("$content.[0].id", equalTo(set.getId().intValue()))) - .andExpect(jsonPath("$content.[0].name", equalTo(set.getName()))) - .andExpect(jsonPath("$content.[0].requiredMigrationStep", equalTo(set.isRequiredMigrationStep()))) - .andExpect(jsonPath("$content.[0].description", equalTo(set.getDescription()))) - .andExpect(jsonPath("$content.[0].type", equalTo(set.getType().getKey()))) - .andExpect(jsonPath("$content.[0].createdBy", equalTo(set.getCreatedBy()))) - .andExpect(jsonPath("$content.[0].createdAt", equalTo(set.getCreatedAt()))) - .andExpect(jsonPath("$content.[0].complete", equalTo(Boolean.TRUE))) - .andExpect(jsonPath("$content.[0].lastModifiedBy", equalTo(set.getLastModifiedBy()))) - .andExpect(jsonPath("$content.[0].lastModifiedAt", equalTo(set.getLastModifiedAt()))) - .andExpect(jsonPath("$content.[0].version", equalTo(set.getVersion()))) - .andExpect(jsonPath("$content.[0].modules.[?(@.type==" + runtimeType.getKey() + ")][0].id", - equalTo(set.findFirstModuleByType(runtimeType).getId().intValue()))) - .andExpect(jsonPath("$content.[0].modules.[?(@.type==" + appType.getKey() + ")][0].id", - equalTo(set.findFirstModuleByType(appType).getId().intValue()))) - .andExpect(jsonPath("$content.[0].modules.[?(@.type==" + osType.getKey() + ")][0].id", - equalTo(set.findFirstModuleByType(osType).getId().intValue()))); + .andExpect(jsonPath("$.content.[0].id", equalTo(set.getId().intValue()))) + .andExpect(jsonPath("$.content.[0].name", equalTo(set.getName()))) + .andExpect(jsonPath("$.content.[0].requiredMigrationStep", equalTo(set.isRequiredMigrationStep()))) + .andExpect(jsonPath("$.content.[0].description", equalTo(set.getDescription()))) + .andExpect(jsonPath("$.content.[0].type", equalTo(set.getType().getKey()))) + .andExpect(jsonPath("$.content.[0].createdBy", equalTo(set.getCreatedBy()))) + .andExpect(jsonPath("$.content.[0].createdAt", equalTo(set.getCreatedAt()))) + .andExpect(jsonPath("$.content.[0].complete", equalTo(Boolean.TRUE))) + .andExpect(jsonPath("$.content.[0].lastModifiedBy", equalTo(set.getLastModifiedBy()))) + .andExpect(jsonPath("$.content.[0].lastModifiedAt", equalTo(set.getLastModifiedAt()))) + .andExpect(jsonPath("$.content.[0].version", equalTo(set.getVersion()))) + .andExpect(jsonPath("$.content.[0].modules.[?(@.type==" + runtimeType.getKey() + ")].id", + contains(set.findFirstModuleByType(runtimeType).getId().intValue()))) + .andExpect(jsonPath("$.content.[0].modules.[?(@.type==" + appType.getKey() + ")].id", + contains(set.findFirstModuleByType(appType).getId().intValue()))) + .andExpect(jsonPath("$.content.[0].modules.[?(@.type==" + osType.getKey() + ")].id", + contains(set.findFirstModuleByType(osType).getId().intValue()))); } @Test @@ -393,25 +394,25 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest mvc.perform(get("/rest/v1/distributionsets/{dsId}", set.getId()).accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(jsonPath("$_links.self.href", + .andExpect(jsonPath("$._links.self.href", equalTo("http://localhost/rest/v1/distributionsets/" + set.getId()))) - .andExpect(jsonPath("$id", equalTo(set.getId().intValue()))) - .andExpect(jsonPath("$name", equalTo(set.getName()))) - .andExpect(jsonPath("$type", equalTo(set.getType().getKey()))) - .andExpect(jsonPath("$description", equalTo(set.getDescription()))) - .andExpect(jsonPath("$requiredMigrationStep", equalTo(set.isRequiredMigrationStep()))) - .andExpect(jsonPath("$createdBy", equalTo(set.getCreatedBy()))) - .andExpect(jsonPath("$complete", equalTo(Boolean.TRUE))) - .andExpect(jsonPath("$createdAt", equalTo(set.getCreatedAt()))) - .andExpect(jsonPath("$lastModifiedBy", equalTo(set.getLastModifiedBy()))) - .andExpect(jsonPath("$lastModifiedAt", equalTo(set.getLastModifiedAt()))) - .andExpect(jsonPath("$version", equalTo(set.getVersion()))) - .andExpect(jsonPath("$modules.[?(@.type==" + runtimeType.getKey() + ")][0].id", - equalTo(set.findFirstModuleByType(runtimeType).getId().intValue()))) - .andExpect(jsonPath("$modules.[?(@.type==" + appType.getKey() + ")][0].id", - equalTo(set.findFirstModuleByType(appType).getId().intValue()))) - .andExpect(jsonPath("$modules.[?(@.type==" + osType.getKey() + ")][0].id", - equalTo(set.findFirstModuleByType(osType).getId().intValue()))); + .andExpect(jsonPath("$.id", equalTo(set.getId().intValue()))) + .andExpect(jsonPath("$.name", equalTo(set.getName()))) + .andExpect(jsonPath("$.type", equalTo(set.getType().getKey()))) + .andExpect(jsonPath("$.description", equalTo(set.getDescription()))) + .andExpect(jsonPath("$.requiredMigrationStep", equalTo(set.isRequiredMigrationStep()))) + .andExpect(jsonPath("$.createdBy", equalTo(set.getCreatedBy()))) + .andExpect(jsonPath("$.complete", equalTo(Boolean.TRUE))) + .andExpect(jsonPath("$.createdAt", equalTo(set.getCreatedAt()))) + .andExpect(jsonPath("$.lastModifiedBy", equalTo(set.getLastModifiedBy()))) + .andExpect(jsonPath("$.lastModifiedAt", equalTo(set.getLastModifiedAt()))) + .andExpect(jsonPath("$.version", equalTo(set.getVersion()))) + .andExpect(jsonPath("$.modules.[?(@.type==" + runtimeType.getKey() + ")].id", + contains(set.findFirstModuleByType(runtimeType).getId().intValue()))) + .andExpect(jsonPath("$.modules.[?(@.type==" + appType.getKey() + ")].id", + contains(set.findFirstModuleByType(appType).getId().intValue()))) + .andExpect(jsonPath("$.modules.[?(@.type==" + osType.getKey() + ")].id", + contains(set.findFirstModuleByType(osType).getId().intValue()))); } @@ -453,24 +454,24 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest .andExpect(jsonPath("[0]version", equalTo(one.getVersion()))) .andExpect(jsonPath("[0]complete", equalTo(Boolean.TRUE))) .andExpect(jsonPath("[0]requiredMigrationStep", equalTo(one.isRequiredMigrationStep()))) - .andExpect(jsonPath("[0].modules.[?(@.type==" + runtimeType.getKey() + ")][0].id", - equalTo(one.findFirstModuleByType(runtimeType).getId().intValue()))) - .andExpect(jsonPath("[0].modules.[?(@.type==" + appType.getKey() + ")][0].id", - equalTo(one.findFirstModuleByType(appType).getId().intValue()))) - .andExpect(jsonPath("[0].modules.[?(@.type==" + osType.getKey() + ")][0].id", - equalTo(one.findFirstModuleByType(osType).getId().intValue()))) + .andExpect(jsonPath("[0].modules.[?(@.type==" + runtimeType.getKey() + ")].id", + contains(one.findFirstModuleByType(runtimeType).getId().intValue()))) + .andExpect(jsonPath("[0].modules.[?(@.type==" + appType.getKey() + ")].id", + contains(one.findFirstModuleByType(appType).getId().intValue()))) + .andExpect(jsonPath("[0].modules.[?(@.type==" + osType.getKey() + ")].id", + contains(one.findFirstModuleByType(osType).getId().intValue()))) .andExpect(jsonPath("[1]name", equalTo(two.getName()))) .andExpect(jsonPath("[1]description", equalTo(two.getDescription()))) .andExpect(jsonPath("[1]complete", equalTo(Boolean.TRUE))) .andExpect(jsonPath("[1]type", equalTo(standardDsType.getKey()))) .andExpect(jsonPath("[1]createdBy", equalTo("uploadTester"))) .andExpect(jsonPath("[1]version", equalTo(two.getVersion()))) - .andExpect(jsonPath("[1].modules.[?(@.type==" + runtimeType.getKey() + ")][0].id", - equalTo(two.findFirstModuleByType(runtimeType).getId().intValue()))) - .andExpect(jsonPath("[1].modules.[?(@.type==" + appType.getKey() + ")][0].id", - equalTo(two.findFirstModuleByType(appType).getId().intValue()))) - .andExpect(jsonPath("[1].modules.[?(@.type==" + osType.getKey() + ")][0].id", - equalTo(two.findFirstModuleByType(osType).getId().intValue()))) + .andExpect(jsonPath("[1].modules.[?(@.type==" + runtimeType.getKey() + ")].id", + contains(two.findFirstModuleByType(runtimeType).getId().intValue()))) + .andExpect(jsonPath("[1].modules.[?(@.type==" + appType.getKey() + ")].id", + contains(two.findFirstModuleByType(appType).getId().intValue()))) + .andExpect(jsonPath("[1].modules.[?(@.type==" + osType.getKey() + ")].id", + contains(two.findFirstModuleByType(osType).getId().intValue()))) .andExpect(jsonPath("[1]requiredMigrationStep", equalTo(two.isRequiredMigrationStep()))) .andExpect(jsonPath("[2]name", equalTo(three.getName()))) .andExpect(jsonPath("[2]description", equalTo(three.getDescription()))) @@ -478,12 +479,12 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest .andExpect(jsonPath("[2]type", equalTo(standardDsType.getKey()))) .andExpect(jsonPath("[2]createdBy", equalTo("uploadTester"))) .andExpect(jsonPath("[2]version", equalTo(three.getVersion()))) - .andExpect(jsonPath("[2].modules.[?(@.type==" + runtimeType.getKey() + ")][0].id", - equalTo(three.findFirstModuleByType(runtimeType).getId().intValue()))) - .andExpect(jsonPath("[2].modules.[?(@.type==" + appType.getKey() + ")][0].id", - equalTo(three.findFirstModuleByType(appType).getId().intValue()))) - .andExpect(jsonPath("[2].modules.[?(@.type==" + osType.getKey() + ")][0].id", - equalTo(three.findFirstModuleByType(osType).getId().intValue()))) + .andExpect(jsonPath("[2].modules.[?(@.type==" + runtimeType.getKey() + ")].id", + contains(three.findFirstModuleByType(runtimeType).getId().intValue()))) + .andExpect(jsonPath("[2].modules.[?(@.type==" + appType.getKey() + ")].id", + contains(three.findFirstModuleByType(appType).getId().intValue()))) + .andExpect(jsonPath("[2].modules.[?(@.type==" + osType.getKey() + ")].id", + contains(three.findFirstModuleByType(osType).getId().intValue()))) .andExpect(jsonPath("[2]requiredMigrationStep", equalTo(three.isRequiredMigrationStep()))).andReturn(); one = distributionSetManagement.findDistributionSetByIdWithDetails( diff --git a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeResourceTest.java b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeResourceTest.java index bc6d69cd3..eba06c5e6 100644 --- a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeResourceTest.java +++ b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeResourceTest.java @@ -11,6 +11,7 @@ package org.eclipse.hawkbit.mgmt.rest.resource; import static org.fest.assertions.api.Assertions.assertThat; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.not; +import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.hasSize; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; @@ -67,29 +68,29 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration mvc.perform(get("/rest/v1/distributionsettypes").accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(jsonPath("$content.[?(@.key==" + standardDsType.getKey() + ")][0].name", - equalTo(standardDsType.getName()))) - .andExpect(jsonPath("$content.[?(@.key==" + standardDsType.getKey() + ")][0].description", - equalTo(standardDsType.getDescription()))) - .andExpect(jsonPath("$content.[?(@.key==" + standardDsType.getKey() + ")][0].key", - equalTo(standardDsType.getKey()))) - .andExpect(jsonPath("$content.[?(@.key==test123)][0].id", equalTo(testType.getId().intValue()))) - .andExpect(jsonPath("$content.[?(@.key==test123)][0].name", equalTo("TestName123"))) - .andExpect(jsonPath("$content.[?(@.key==test123)][0].description", equalTo("Desc1234"))) - .andExpect(jsonPath("$content.[?(@.key==test123)][0].createdBy", equalTo("uploadTester"))) - .andExpect(jsonPath("$content.[?(@.key==test123)][0].createdAt", equalTo(testType.getCreatedAt()))) - .andExpect(jsonPath("$content.[?(@.key==test123)][0].lastModifiedBy", equalTo("uploadTester"))) - .andExpect(jsonPath("$content.[?(@.key==test123)][0].lastModifiedAt", - equalTo(testType.getLastModifiedAt()))) - .andExpect(jsonPath("$content.[?(@.key==test123)][0].key", equalTo("test123"))) - .andExpect(jsonPath("$content.[?(@.key==test123)][0]._links.self.href", - equalTo("http://localhost/rest/v1/distributionsettypes/" + testType.getId()))) - .andExpect(jsonPath("$content.[?(@.key==test123)][0]._links.mandatorymodules.href", - equalTo("http://localhost/rest/v1/distributionsettypes/" + testType.getId() + .andExpect(jsonPath("$.content.[?(@.key==" + standardDsType.getKey() + ")]$..name", + contains(standardDsType.getName()))) + .andExpect(jsonPath("$.content.[?(@.key==" + standardDsType.getKey() + ")]$..description", + contains(standardDsType.getDescription()))) + .andExpect(jsonPath("$.content.[?(@.key==" + standardDsType.getKey() + ")]$..key", + contains(standardDsType.getKey()))) + .andExpect(jsonPath("$.content.[?(@.key==test123)]$..id", contains(testType.getId().intValue()))) + .andExpect(jsonPath("$.content.[?(@.key==test123)]$..name", contains("TestName123"))) + .andExpect(jsonPath("$.content.[?(@.key==test123)]$..description", contains("Desc1234"))) + .andExpect(jsonPath("$.content.[?(@.key==test123)]$..createdBy", contains("uploadTester"))) + .andExpect(jsonPath("$.content.[?(@.key==test123)]$..createdAt", contains(testType.getCreatedAt()))) + .andExpect(jsonPath("$.content.[?(@.key==test123)]$..lastModifiedBy", contains("uploadTester"))) + .andExpect(jsonPath("$.content.[?(@.key==test123)]$..lastModifiedAt", + contains(testType.getLastModifiedAt()))) + .andExpect(jsonPath("$.content.[?(@.key==test123)]$..key", contains("test123"))) + .andExpect(jsonPath("$.content.[?(@.key==test123)]$.._links.self.href", + contains("http://localhost/rest/v1/distributionsettypes/" + testType.getId()))) + .andExpect(jsonPath("$.content.[?(@.key==test123)]$.._links.mandatorymodules.href", + contains("http://localhost/rest/v1/distributionsettypes/" + testType.getId() + "/mandatorymoduletypes"))) - .andExpect(jsonPath("$content.[?(@.key==test123)][0]._links.optionalmodules.href", equalTo( + .andExpect(jsonPath("$.content.[?(@.key==test123)]$.._links.optionalmodules.href", contains( "http://localhost/rest/v1/distributionsettypes/" + testType.getId() + "/optionalmoduletypes"))) - .andExpect(jsonPath("$total", equalTo(4))); + .andExpect(jsonPath("$.total", equalTo(4))); } @Test @@ -106,29 +107,29 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration mvc.perform(get("/rest/v1/distributionsettypes").accept(MediaType.APPLICATION_JSON) .param(MgmtRestConstants.REQUEST_PARAMETER_SORTING, "KEY:DESC")).andDo(MockMvcResultPrinter.print()) .andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(jsonPath("$content.[0].id", equalTo(testType.getId().intValue()))) - .andExpect(jsonPath("$content.[0].name", equalTo("TestName123"))) - .andExpect(jsonPath("$content.[0].description", equalTo("Desc1234"))) - .andExpect(jsonPath("$content.[0].createdBy", equalTo("uploadTester"))) - .andExpect(jsonPath("$content.[0].createdAt", equalTo(testType.getCreatedAt()))) - .andExpect(jsonPath("$content.[0].lastModifiedBy", equalTo("uploadTester"))) - .andExpect(jsonPath("$content.[0].lastModifiedAt", equalTo(testType.getLastModifiedAt()))) - .andExpect(jsonPath("$content.[0].key", equalTo("zzzzz"))) - .andExpect(jsonPath("$total", equalTo(DEFAULT_DS_TYPES + 1))); + .andExpect(jsonPath("$.content.[0].id", equalTo(testType.getId().intValue()))) + .andExpect(jsonPath("$.content.[0].name", equalTo("TestName123"))) + .andExpect(jsonPath("$.content.[0].description", equalTo("Desc1234"))) + .andExpect(jsonPath("$.content.[0].createdBy", equalTo("uploadTester"))) + .andExpect(jsonPath("$.content.[0].createdAt", equalTo(testType.getCreatedAt()))) + .andExpect(jsonPath("$.content.[0].lastModifiedBy", equalTo("uploadTester"))) + .andExpect(jsonPath("$.content.[0].lastModifiedAt", equalTo(testType.getLastModifiedAt()))) + .andExpect(jsonPath("$.content.[0].key", equalTo("zzzzz"))) + .andExpect(jsonPath("$.total", equalTo(DEFAULT_DS_TYPES + 1))); // ascending mvc.perform(get("/rest/v1/distributionsettypes").accept(MediaType.APPLICATION_JSON) .param(MgmtRestConstants.REQUEST_PARAMETER_SORTING, "KEY:ASC")).andDo(MockMvcResultPrinter.print()) .andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(jsonPath("$content.[3].id", equalTo(testType.getId().intValue()))) - .andExpect(jsonPath("$content.[3].name", equalTo("TestName123"))) - .andExpect(jsonPath("$content.[3].description", equalTo("Desc1234"))) - .andExpect(jsonPath("$content.[3].createdBy", equalTo("uploadTester"))) - .andExpect(jsonPath("$content.[3].createdAt", equalTo(testType.getCreatedAt()))) - .andExpect(jsonPath("$content.[3].lastModifiedBy", equalTo("uploadTester"))) - .andExpect(jsonPath("$content.[3].lastModifiedAt", equalTo(testType.getLastModifiedAt()))) - .andExpect(jsonPath("$content.[3].key", equalTo("zzzzz"))) - .andExpect(jsonPath("$total", equalTo(DEFAULT_DS_TYPES + 1))); + .andExpect(jsonPath("$.content.[3].id", equalTo(testType.getId().intValue()))) + .andExpect(jsonPath("$.content.[3].name", equalTo("TestName123"))) + .andExpect(jsonPath("$.content.[3].description", equalTo("Desc1234"))) + .andExpect(jsonPath("$.content.[3].createdBy", equalTo("uploadTester"))) + .andExpect(jsonPath("$.content.[3].createdAt", equalTo(testType.getCreatedAt()))) + .andExpect(jsonPath("$.content.[3].lastModifiedBy", equalTo("uploadTester"))) + .andExpect(jsonPath("$.content.[3].lastModifiedAt", equalTo(testType.getLastModifiedAt()))) + .andExpect(jsonPath("$.content.[3].key", equalTo("zzzzz"))) + .andExpect(jsonPath("$.total", equalTo(DEFAULT_DS_TYPES + 1))); } @Test @@ -141,8 +142,8 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration final List types = new ArrayList<>(); types.add(entityFactory.generateDistributionSetType("test1", "TestName1", "Desc1") .addMandatoryModuleType(osType).addOptionalModuleType(runtimeType)); - types.add(entityFactory.generateDistributionSetType("test2", "TestName2", "Desc2") - .addOptionalModuleType(osType).addOptionalModuleType(runtimeType).addOptionalModuleType(appType)); + types.add(entityFactory.generateDistributionSetType("test2", "TestName2", "Desc2").addOptionalModuleType(osType) + .addOptionalModuleType(runtimeType).addOptionalModuleType(appType)); types.add(entityFactory.generateDistributionSetType("test3", "TestName3", "Desc3") .addMandatoryModuleType(osType).addMandatoryModuleType(runtimeType)); @@ -295,13 +296,13 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration mvc.perform(get("/rest/v1/distributionsettypes/{dstID}/mandatorymoduletypes/{smtId}", testType.getId(), osType.getId()).contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print()) - .andExpect(status().isOk()).andExpect(jsonPath("$id", equalTo(osType.getId().intValue()))) - .andExpect(jsonPath("$name", equalTo(osType.getName()))) - .andExpect(jsonPath("$description", equalTo(osType.getDescription()))) - .andExpect(jsonPath("$createdBy", equalTo(osType.getCreatedBy()))) - .andExpect(jsonPath("$createdAt", equalTo(osType.getCreatedAt()))) - .andExpect(jsonPath("$lastModifiedBy", equalTo(osType.getLastModifiedBy()))) - .andExpect(jsonPath("$lastModifiedAt", equalTo(osType.getLastModifiedAt()))); + .andExpect(status().isOk()).andExpect(jsonPath("$.id", equalTo(osType.getId().intValue()))) + .andExpect(jsonPath("$.name", equalTo(osType.getName()))) + .andExpect(jsonPath("$.description", equalTo(osType.getDescription()))) + .andExpect(jsonPath("$.createdBy", equalTo(osType.getCreatedBy()))) + .andExpect(jsonPath("$.createdAt", equalTo(osType.getCreatedAt()))) + .andExpect(jsonPath("$.lastModifiedBy", equalTo(osType.getLastModifiedBy()))) + .andExpect(jsonPath("$.lastModifiedAt", equalTo(osType.getLastModifiedAt()))); } @Test @@ -317,13 +318,13 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration mvc.perform(get("/rest/v1/distributionsettypes/{dstID}/optionalmoduletypes/{smtId}", testType.getId(), appType.getId()).contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print()) - .andExpect(status().isOk()).andExpect(jsonPath("$id", equalTo(appType.getId().intValue()))) - .andExpect(jsonPath("$name", equalTo(appType.getName()))) - .andExpect(jsonPath("$description", equalTo(appType.getDescription()))) - .andExpect(jsonPath("$createdBy", equalTo(appType.getCreatedBy()))) - .andExpect(jsonPath("$createdAt", equalTo(appType.getCreatedAt()))) - .andExpect(jsonPath("$lastModifiedBy", equalTo(appType.getLastModifiedBy()))) - .andExpect(jsonPath("$lastModifiedAt", equalTo(appType.getLastModifiedAt()))); + .andExpect(status().isOk()).andExpect(jsonPath("$.id", equalTo(appType.getId().intValue()))) + .andExpect(jsonPath("$.name", equalTo(appType.getName()))) + .andExpect(jsonPath("$.description", equalTo(appType.getDescription()))) + .andExpect(jsonPath("$.createdBy", equalTo(appType.getCreatedBy()))) + .andExpect(jsonPath("$.createdAt", equalTo(appType.getCreatedAt()))) + .andExpect(jsonPath("$.lastModifiedBy", equalTo(appType.getLastModifiedBy()))) + .andExpect(jsonPath("$.lastModifiedAt", equalTo(appType.getLastModifiedAt()))); } @Test @@ -383,11 +384,11 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration mvc.perform(get("/rest/v1/distributionsettypes/{dstId}", testType.getId()).accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(jsonPath("$name", equalTo("TestName123"))) - .andExpect(jsonPath("$description", equalTo("Desc1234"))) - .andExpect(jsonPath("$createdBy", equalTo("uploadTester"))) - .andExpect(jsonPath("$createdAt", equalTo(testType.getCreatedAt()))) - .andExpect(jsonPath("$lastModifiedBy", equalTo("uploadTester"))); + .andExpect(jsonPath("$.name", equalTo("TestName123"))) + .andExpect(jsonPath("$.description", equalTo("Desc1234"))) + .andExpect(jsonPath("$.createdBy", equalTo("uploadTester"))) + .andExpect(jsonPath("$.createdAt", equalTo(testType.getCreatedAt()))) + .andExpect(jsonPath("$.lastModifiedBy", equalTo("uploadTester"))); } @Test @@ -435,9 +436,9 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration mvc.perform(put("/rest/v1/distributionsettypes/{smId}", testType.getId()).content(body) .contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) - .andExpect(jsonPath("$id", equalTo(testType.getId().intValue()))) - .andExpect(jsonPath("$description", equalTo("foobardesc"))) - .andExpect(jsonPath("$name", equalTo("TestName123"))).andReturn(); + .andExpect(jsonPath("$.id", equalTo(testType.getId().intValue()))) + .andExpect(jsonPath("$.description", equalTo("foobardesc"))) + .andExpect(jsonPath("$.name", equalTo("TestName123"))).andReturn(); } @Test @@ -533,8 +534,8 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration // Modules types at creation time invalid - final DistributionSetType testNewType = entityFactory.generateDistributionSetType("test123", - "TestName123", "Desc123"); + final DistributionSetType testNewType = entityFactory.generateDistributionSetType("test123", "TestName123", + "Desc123"); testNewType.addMandatoryModuleType( entityFactory.generateSoftwareModuleType("foo", "bar", "test", Integer.MAX_VALUE)); diff --git a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutResourceTest.java b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutResourceTest.java index 11536e6e1..e495c0d9d 100644 --- a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutResourceTest.java +++ b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutResourceTest.java @@ -29,9 +29,9 @@ import org.eclipse.hawkbit.repository.model.Rollout; import org.eclipse.hawkbit.repository.model.Rollout.RolloutStatus; import org.eclipse.hawkbit.repository.model.RolloutGroup; import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupSuccessCondition; -import org.eclipse.hawkbit.repository.test.util.WithUser; import org.eclipse.hawkbit.repository.model.RolloutGroupConditionBuilder; import org.eclipse.hawkbit.repository.model.Target; +import org.eclipse.hawkbit.repository.test.util.WithUser; import org.eclipse.hawkbit.rest.AbstractRestIntegrationTest; import org.eclipse.hawkbit.rest.util.JsonBuilder; import org.eclipse.hawkbit.rest.util.MockMvcResultPrinter; @@ -126,7 +126,7 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest { public void noRolloutReturnsEmptyList() throws Exception { mvc.perform(get("/rest/v1/rollouts")).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(jsonPath("$content", hasSize(0))).andExpect(jsonPath("$total", equalTo(0))); + .andExpect(jsonPath("$.content", hasSize(0))).andExpect(jsonPath("$.total", equalTo(0))); } @Test @@ -139,7 +139,7 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest { mvc.perform(get("/rest/v1/rollouts")).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(jsonPath("$content", hasSize(2))).andExpect(jsonPath("$total", equalTo(2))) + .andExpect(jsonPath("$.content", hasSize(2))).andExpect(jsonPath("$.total", equalTo(2))) .andExpect(jsonPath("content[0].name", equalTo("rollout1"))) .andExpect(jsonPath("content[0].status", equalTo("ready"))) .andExpect(jsonPath("content[0].targetFilterQuery", equalTo("name==target1"))) @@ -160,7 +160,7 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest { mvc.perform(get("/rest/v1/rollouts?limit=1")).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(jsonPath("$content", hasSize(1))).andExpect(jsonPath("$total", equalTo(2))); + .andExpect(jsonPath("$.content", hasSize(1))).andExpect(jsonPath("$.total", equalTo(2))); } @Test @@ -178,11 +178,11 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest { mvc.perform(get("/rest/v1/rollouts/{rolloutId}/deploygroups", rollout.getId())) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(jsonPath("$content", hasSize(4))).andExpect(jsonPath("$total", equalTo(4))) - .andExpect(jsonPath("$content[0].status", equalTo("ready"))) - .andExpect(jsonPath("$content[1].status", equalTo("ready"))) - .andExpect(jsonPath("$content[2].status", equalTo("ready"))) - .andExpect(jsonPath("$content[3].status", equalTo("ready"))); + .andExpect(jsonPath("$.content", hasSize(4))).andExpect(jsonPath("$.total", equalTo(4))) + .andExpect(jsonPath("$.content[0].status", equalTo("ready"))) + .andExpect(jsonPath("$.content[1].status", equalTo("ready"))) + .andExpect(jsonPath("$.content[2].status", equalTo("ready"))) + .andExpect(jsonPath("$.content[3].status", equalTo("ready"))); } @Test @@ -321,9 +321,9 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest { mvc.perform(get("/rest/v1/rollouts/{rolloutId}/deploygroups?sort=ID:ASC", rollout.getId())) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(jsonPath("$content", hasSize(2))).andExpect(jsonPath("$total", equalTo(2))) - .andExpect(jsonPath("$content[0].status", equalTo("running"))) - .andExpect(jsonPath("$content[1].status", equalTo("scheduled"))); + .andExpect(jsonPath("$.content", hasSize(2))).andExpect(jsonPath("$.total", equalTo(2))) + .andExpect(jsonPath("$.content[0].status", equalTo("running"))) + .andExpect(jsonPath("$.content[1].status", equalTo("scheduled"))); } @Test @@ -368,7 +368,7 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest { mvc.perform(get("/rest/v1/rollouts/{rolloutId}/deploygroups/{groupId}/targets", rollout.getId(), firstGroup.getId())).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(jsonPath("$content", hasSize(5))).andExpect(jsonPath("$total", equalTo(5))); + .andExpect(jsonPath("$.content", hasSize(5))).andExpect(jsonPath("$.total", equalTo(5))); } @Test @@ -393,7 +393,7 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest { .param("q", "controllerId==" + targets.get(0).getControllerId())) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(jsonPath("$content", hasSize(1))).andExpect(jsonPath("$total", equalTo(1))); + .andExpect(jsonPath("$.content", hasSize(1))).andExpect(jsonPath("$.total", equalTo(1))); } @Test @@ -417,7 +417,7 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest { mvc.perform(get("/rest/v1/rollouts/{rolloutId}/deploygroups/{groupId}/targets", rollout.getId(), firstGroup.getId())).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(jsonPath("$content", hasSize(5))).andExpect(jsonPath("$total", equalTo(5))); + .andExpect(jsonPath("$.content", hasSize(5))).andExpect(jsonPath("$.total", equalTo(5))); } @Test @@ -449,12 +449,9 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest { final int amountTargetsRollout2 = 25; final int amountTargetsRollout3 = 25; final int amountTargetsOther = 25; - targetManagement - .createTargets(testdataFactory.generateTargets(amountTargetsRollout1, "rollout1", "rollout1")); - targetManagement - .createTargets(testdataFactory.generateTargets(amountTargetsRollout2, "rollout2", "rollout2")); - targetManagement - .createTargets(testdataFactory.generateTargets(amountTargetsRollout3, "rollout3", "rollout3")); + targetManagement.createTargets(testdataFactory.generateTargets(amountTargetsRollout1, "rollout1", "rollout1")); + targetManagement.createTargets(testdataFactory.generateTargets(amountTargetsRollout2, "rollout2", "rollout2")); + targetManagement.createTargets(testdataFactory.generateTargets(amountTargetsRollout3, "rollout3", "rollout3")); targetManagement.createTargets(testdataFactory.generateTargets(amountTargetsOther, "other1", "other1")); final DistributionSet dsA = testdataFactory.createDistributionSet(""); @@ -466,18 +463,18 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest { mvc.perform(get("/rest/v1/rollouts").param(MgmtRestConstants.REQUEST_PARAMETER_SEARCH, "name==*2")) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(jsonPath("$content", hasSize(1))).andExpect(jsonPath("$total", equalTo(1))) - .andExpect(jsonPath("$content[0].name", equalTo(rollout2.getName()))); + .andExpect(jsonPath("$.content", hasSize(1))).andExpect(jsonPath("$.total", equalTo(1))) + .andExpect(jsonPath("$.content[0].name", equalTo(rollout2.getName()))); mvc.perform(get("/rest/v1/rollouts").param(MgmtRestConstants.REQUEST_PARAMETER_SEARCH, "name==rollout*")) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(jsonPath("$content", hasSize(3))).andExpect(jsonPath("$total", equalTo(3))); + .andExpect(jsonPath("$.content", hasSize(3))).andExpect(jsonPath("$.total", equalTo(3))); mvc.perform(get("/rest/v1/rollouts").param(MgmtRestConstants.REQUEST_PARAMETER_SEARCH, "name==*1")) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(jsonPath("$content", hasSize(2))).andExpect(jsonPath("$total", equalTo(2))); + .andExpect(jsonPath("$.content", hasSize(2))).andExpect(jsonPath("$.total", equalTo(2))); } @@ -496,19 +493,19 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest { mvc.perform(get("/rest/v1/rollouts/{rolloutId}/deploygroups", rollout.getId()) .param(MgmtRestConstants.REQUEST_PARAMETER_SEARCH, "name==group-1")).andDo(MockMvcResultPrinter.print()) .andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(jsonPath("$content", hasSize(1))).andExpect(jsonPath("$total", equalTo(1))) - .andExpect(jsonPath("$content[0].name", equalTo("group-1"))); + .andExpect(jsonPath("$.content", hasSize(1))).andExpect(jsonPath("$.total", equalTo(1))) + .andExpect(jsonPath("$.content[0].name", equalTo("group-1"))); mvc.perform(get("/rest/v1/rollouts/{rolloutId}/deploygroups", rollout.getId()) .param(MgmtRestConstants.REQUEST_PARAMETER_SEARCH, "name==group*")).andDo(MockMvcResultPrinter.print()) .andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(jsonPath("$content", hasSize(4))).andExpect(jsonPath("$total", equalTo(4))); + .andExpect(jsonPath("$.content", hasSize(4))).andExpect(jsonPath("$.total", equalTo(4))); mvc.perform(get("/rest/v1/rollouts/{rolloutId}/deploygroups", rollout.getId()) .param(MgmtRestConstants.REQUEST_PARAMETER_SEARCH, "name==group-1,name==group-2")) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(jsonPath("$content", hasSize(2))).andExpect(jsonPath("$total", equalTo(2))); + .andExpect(jsonPath("$.content", hasSize(2))).andExpect(jsonPath("$.total", equalTo(2))); } diff --git a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResourceTest.java b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResourceTest.java index 79a3fc2b2..1703e5c0e 100644 --- a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResourceTest.java +++ b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResourceTest.java @@ -11,6 +11,7 @@ package org.eclipse.hawkbit.mgmt.rest.resource; import static org.fest.assertions.api.Assertions.assertThat; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.not; +import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.hasSize; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -89,8 +90,8 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW final String updateVendor = "newVendor1"; final String updateDescription = "newDescription1"; - softwareManagement.createSoftwareModule( - entityFactory.generateSoftwareModule(appType, "agent-hub", "1.0.1", null, "")); + softwareManagement + .createSoftwareModule(entityFactory.generateSoftwareModule(appType, "agent-hub", "1.0.1", null, "")); softwareManagement.createSoftwareModule( entityFactory.generateSoftwareModule(runtimeType, "oracle-jre", "1.7.2", null, "")); softwareManagement @@ -111,12 +112,12 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW mvc.perform(put("/rest/v1/softwaremodules/{smId}", sm.getId()).content(body) .contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) - .andExpect(jsonPath("$id", equalTo(sm.getId().intValue()))) - .andExpect(jsonPath("$vendor", equalTo(updateVendor))) - .andExpect(jsonPath("$lastModifiedBy", equalTo("smUpdateTester"))) - .andExpect(jsonPath("$lastModifiedAt", not(equalTo(sm.getLastModifiedAt())))) - .andExpect(jsonPath("$description", equalTo(updateDescription))) - .andExpect(jsonPath("$name", equalTo(knownSWName))).andReturn(); + .andExpect(jsonPath("$.id", equalTo(sm.getId().intValue()))) + .andExpect(jsonPath("$.vendor", equalTo(updateVendor))) + .andExpect(jsonPath("$.lastModifiedBy", equalTo("smUpdateTester"))) + .andExpect(jsonPath("$.lastModifiedAt", not(equalTo(sm.getLastModifiedAt())))) + .andExpect(jsonPath("$.description", equalTo(updateDescription))) + .andExpect(jsonPath("$.name", equalTo(knownSWName))).andReturn(); } @@ -138,10 +139,10 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW .accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isCreated()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(jsonPath("$type", equalTo("local"))).andExpect(jsonPath("$hashes.md5", equalTo(md5sum))) - .andExpect(jsonPath("$hashes.sha1", equalTo(sha1sum))) - .andExpect(jsonPath("$size", equalTo(random.length))) - .andExpect(jsonPath("$providedFilename", equalTo("origFilename"))).andReturn(); + .andExpect(jsonPath("$.type", equalTo("local"))).andExpect(jsonPath("$.hashes.md5", equalTo(md5sum))) + .andExpect(jsonPath("$.hashes.sha1", equalTo(sha1sum))) + .andExpect(jsonPath("$.size", equalTo(random.length))) + .andExpect(jsonPath("$.providedFilename", equalTo("origFilename"))).andReturn(); // check rest of response compared to DB final MgmtArtifact artResult = ResourceUtility @@ -149,13 +150,12 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW final Long artId = ((LocalArtifact) softwareManagement.findSoftwareModuleWithDetails(sm.getId()).getArtifacts() .get(0)).getId(); assertThat(artResult.getArtifactId()).as("Wrong artifact id").isEqualTo(artId); - assertThat(JsonPath.compile("$_links.self.href").read(mvcResult.getResponse().getContentAsString()).toString()) + assertThat(JsonPath.compile("$._links.self.href").read(mvcResult.getResponse().getContentAsString()).toString()) .as("Link contains no self url") .isEqualTo("http://localhost/rest/v1/softwaremodules/" + sm.getId() + "/artifacts/" + artId); - assertThat( - JsonPath.compile("$_links.download.href").read(mvcResult.getResponse().getContentAsString()).toString()) - .as("response contains no download url ").isEqualTo("http://localhost/rest/v1/softwaremodules/" - + sm.getId() + "/artifacts/" + artId + "/download"); + assertThat(JsonPath.compile("$._links.download.href").read(mvcResult.getResponse().getContentAsString()) + .toString()).as("response contains no download url ").isEqualTo( + "http://localhost/rest/v1/softwaremodules/" + sm.getId() + "/artifacts/" + artId + "/download"); assertArtifact(sm, random); } @@ -215,9 +215,9 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW mvc.perform(fileUpload("/rest/v1/softwaremodules/{smId}/artifacts", sm.getId()).file(file) .accept(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print()).andExpect(status().isCreated()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(jsonPath("$type", equalTo("local"))).andExpect(jsonPath("$hashes.md5", equalTo(md5sum))) - .andExpect(jsonPath("$hashes.sha1", equalTo(sha1sum))) - .andExpect(jsonPath("$providedFilename", equalTo("orig"))).andExpect(status().isCreated()); + .andExpect(jsonPath("$.type", equalTo("local"))).andExpect(jsonPath("$.hashes.md5", equalTo(md5sum))) + .andExpect(jsonPath("$.hashes.sha1", equalTo(sha1sum))) + .andExpect(jsonPath("$.providedFilename", equalTo("orig"))).andExpect(status().isCreated()); mvc.perform(fileUpload("/rest/v1/softwaremodules/{smId}/artifacts", sm.getId()).file(file)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isConflict()); @@ -239,7 +239,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW .param("filename", "customFilename").accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isCreated()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(jsonPath("$providedFilename", equalTo("customFilename"))).andExpect(status().isCreated()); + .andExpect(jsonPath("$.providedFilename", equalTo("customFilename"))).andExpect(status().isCreated()); // check result in db... // repo @@ -343,15 +343,15 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW mvc.perform(get("/rest/v1/softwaremodules/{smId}/artifacts/{artId}", sm.getId(), artifact.getId()) .accept(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(jsonPath("$id", equalTo(artifact.getId().intValue()))) - .andExpect(jsonPath("$type", equalTo("local"))).andExpect(jsonPath("$size", equalTo(random.length))) - .andExpect(jsonPath("$hashes.md5", equalTo(artifact.getMd5Hash()))) - .andExpect(jsonPath("$hashes.sha1", equalTo(artifact.getSha1Hash()))) - .andExpect(jsonPath("$providedFilename", equalTo("file1"))) - .andExpect(jsonPath("$_links.download.href", + .andExpect(jsonPath("$.id", equalTo(artifact.getId().intValue()))) + .andExpect(jsonPath("$.type", equalTo("local"))).andExpect(jsonPath("$.size", equalTo(random.length))) + .andExpect(jsonPath("$.hashes.md5", equalTo(artifact.getMd5Hash()))) + .andExpect(jsonPath("$.hashes.sha1", equalTo(artifact.getSha1Hash()))) + .andExpect(jsonPath("$.providedFilename", equalTo("file1"))) + .andExpect(jsonPath("$._links.download.href", equalTo("http://localhost/rest/v1/softwaremodules/" + sm.getId() + "/artifacts/" + artifact.getId() + "/download"))) - .andExpect(jsonPath("$_links.self.href", equalTo( + .andExpect(jsonPath("$._links.self.href", equalTo( "http://localhost/rest/v1/softwaremodules/" + sm.getId() + "/artifacts/" + artifact.getId()))); } @@ -371,27 +371,27 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW mvc.perform(get("/rest/v1/softwaremodules/{smId}/artifacts", sm.getId()).accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(jsonPath("$[0].id", equalTo(artifact.getId().intValue()))) - .andExpect(jsonPath("$[0].type", equalTo("local"))) - .andExpect(jsonPath("$[0].size", equalTo(random.length))) - .andExpect(jsonPath("$[0].hashes.md5", equalTo(artifact.getMd5Hash()))) - .andExpect(jsonPath("$[0].hashes.sha1", equalTo(artifact.getSha1Hash()))) - .andExpect(jsonPath("$[0].providedFilename", equalTo("file1"))) - .andExpect(jsonPath("$[0]._links.download.href", + .andExpect(jsonPath("$.[0].id", equalTo(artifact.getId().intValue()))) + .andExpect(jsonPath("$.[0].type", equalTo("local"))) + .andExpect(jsonPath("$.[0].size", equalTo(random.length))) + .andExpect(jsonPath("$.[0].hashes.md5", equalTo(artifact.getMd5Hash()))) + .andExpect(jsonPath("$.[0].hashes.sha1", equalTo(artifact.getSha1Hash()))) + .andExpect(jsonPath("$.[0].providedFilename", equalTo("file1"))) + .andExpect(jsonPath("$.[0]._links.download.href", equalTo("http://localhost/rest/v1/softwaremodules/" + sm.getId() + "/artifacts/" + artifact.getId() + "/download"))) - .andExpect(jsonPath("$[0]._links.self.href", + .andExpect(jsonPath("$.[0]._links.self.href", equalTo("http://localhost/rest/v1/softwaremodules/" + sm.getId() + "/artifacts/" + artifact.getId()))) - .andExpect(jsonPath("$[1].id", equalTo(artifact2.getId().intValue()))) - .andExpect(jsonPath("$[1].type", equalTo("local"))) - .andExpect(jsonPath("$[1].hashes.md5", equalTo(artifact2.getMd5Hash()))) - .andExpect(jsonPath("$[1].hashes.sha1", equalTo(artifact2.getSha1Hash()))) - .andExpect(jsonPath("$[1].providedFilename", equalTo("file2"))) - .andExpect(jsonPath("$[1]._links.download.href", + .andExpect(jsonPath("$.[1].id", equalTo(artifact2.getId().intValue()))) + .andExpect(jsonPath("$.[1].type", equalTo("local"))) + .andExpect(jsonPath("$.[1].hashes.md5", equalTo(artifact2.getMd5Hash()))) + .andExpect(jsonPath("$.[1].hashes.sha1", equalTo(artifact2.getSha1Hash()))) + .andExpect(jsonPath("$.[1].providedFilename", equalTo("file2"))) + .andExpect(jsonPath("$.[1]._links.download.href", equalTo("http://localhost/rest/v1/softwaremodules/" + sm.getId() + "/artifacts/" + artifact2.getId() + "/download"))) - .andExpect(jsonPath("$[1]._links.self.href", equalTo( + .andExpect(jsonPath("$.[1]._links.self.href", equalTo( "http://localhost/rest/v1/softwaremodules/" + sm.getId() + "/artifacts/" + artifact2.getId()))); } @@ -531,55 +531,54 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW mvc.perform(get("/rest/v1/softwaremodules").accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(jsonPath("$content.[?(@.id==" + os.getId() + ")][0].name", equalTo("name1"))) - .andExpect(jsonPath("$content.[?(@.id==" + os.getId() + ")][0].version", equalTo("version1"))) - .andExpect(jsonPath("$content.[?(@.id==" + os.getId() + ")][0].description", equalTo("description1"))) - .andExpect(jsonPath("$content.[?(@.id==" + os.getId() + ")][0].vendor", equalTo("vendor1"))) - .andExpect(jsonPath("$content.[?(@.id==" + os.getId() + ")][0].type", equalTo("os"))) - .andExpect(jsonPath("$content.[?(@.id==" + os.getId() + ")][0].createdBy", equalTo("uploadTester"))) - .andExpect(jsonPath("$content.[?(@.id==" + os.getId() + ")][0].createdAt", equalTo(os.getCreatedAt()))) - .andExpect(jsonPath("$content.[?(@.id==" + os.getId() + ")][0]._links.type.href", - equalTo("http://localhost/rest/v1/softwaremoduletypes/" + osType.getId()))) - .andExpect(jsonPath("$content.[?(@.id==" + os.getId() + ")][0]._links.self.href", - equalTo("http://localhost/rest/v1/softwaremodules/" + os.getId()))) - .andExpect(jsonPath("$content.[?(@.id==" + os.getId() + ")][0]._links.artifacts.href", - equalTo("http://localhost/rest/v1/softwaremodules/" + os.getId() + "/artifacts"))) - .andExpect(jsonPath("$content.[?(@.id==" + os.getId() + ")][0]._links.metadata.href", - equalTo("http://localhost/rest/v1/softwaremodules/" + os.getId() + .andExpect(jsonPath("$.content.[?(@.id==" + os.getId() + ")].name", contains("name1"))) + .andExpect(jsonPath("$.content.[?(@.id==" + os.getId() + ")].version", contains("version1"))) + .andExpect(jsonPath("$.content.[?(@.id==" + os.getId() + ")].description", contains("description1"))) + .andExpect(jsonPath("$.content.[?(@.id==" + os.getId() + ")].vendor", contains("vendor1"))) + .andExpect(jsonPath("$.content.[?(@.id==" + os.getId() + ")].type", contains("os"))) + .andExpect(jsonPath("$.content.[?(@.id==" + os.getId() + ")].createdBy", contains("uploadTester"))) + .andExpect(jsonPath("$.content.[?(@.id==" + os.getId() + ")].createdAt", contains(os.getCreatedAt()))) + .andExpect(jsonPath("$.content.[?(@.id==" + os.getId() + ")]._links.type.href", + contains("http://localhost/rest/v1/softwaremoduletypes/" + osType.getId()))) + .andExpect(jsonPath("$.content.[?(@.id==" + os.getId() + ")]._links.self.href", + contains("http://localhost/rest/v1/softwaremodules/" + os.getId()))) + .andExpect(jsonPath("$.content.[?(@.id==" + os.getId() + ")]._links.artifacts.href", + contains("http://localhost/rest/v1/softwaremodules/" + os.getId() + "/artifacts"))) + .andExpect(jsonPath("$.content.[?(@.id==" + os.getId() + ")]._links.metadata.href", + contains("http://localhost/rest/v1/softwaremodules/" + os.getId() + "/metadata?offset=0&limit=50"))) - .andExpect(jsonPath("$content.[?(@.id==" + jvm.getId() + ")][0].name", equalTo("name1"))) - .andExpect(jsonPath("$content.[?(@.id==" + jvm.getId() + ")][0].version", equalTo("version1"))) - .andExpect(jsonPath("$content.[?(@.id==" + jvm.getId() + ")][0].description", equalTo("description1"))) - .andExpect(jsonPath("$content.[?(@.id==" + jvm.getId() + ")][0].vendor", equalTo("vendor1"))) - .andExpect(jsonPath("$content.[?(@.id==" + jvm.getId() + ")][0].type", equalTo("runtime"))) - .andExpect(jsonPath("$content.[?(@.id==" + jvm.getId() + ")][0].createdBy", equalTo("uploadTester"))) - .andExpect( - jsonPath("$content.[?(@.id==" + jvm.getId() + ")][0].createdAt", equalTo(jvm.getCreatedAt()))) - .andExpect(jsonPath("$content.[?(@.id==" + jvm.getId() + ")][0]._links.type.href", - equalTo("http://localhost/rest/v1/softwaremoduletypes/" + runtimeType.getId()))) - .andExpect(jsonPath("$content.[?(@.id==" + jvm.getId() + ")][0]._links.self.href", - equalTo("http://localhost/rest/v1/softwaremodules/" + jvm.getId()))) - .andExpect(jsonPath("$content.[?(@.id==" + jvm.getId() + ")][0]._links.artifacts.href", - equalTo("http://localhost/rest/v1/softwaremodules/" + jvm.getId() + "/artifacts"))) - .andExpect(jsonPath("$content.[?(@.id==" + jvm.getId() + ")][0]._links.metadata.href", - equalTo("http://localhost/rest/v1/softwaremodules/" + jvm.getId() + .andExpect(jsonPath("$.content.[?(@.id==" + jvm.getId() + ")].name", contains("name1"))) + .andExpect(jsonPath("$.content.[?(@.id==" + jvm.getId() + ")].version", contains("version1"))) + .andExpect(jsonPath("$.content.[?(@.id==" + jvm.getId() + ")].description", contains("description1"))) + .andExpect(jsonPath("$.content.[?(@.id==" + jvm.getId() + ")].vendor", contains("vendor1"))) + .andExpect(jsonPath("$.content.[?(@.id==" + jvm.getId() + ")].type", contains("runtime"))) + .andExpect(jsonPath("$.content.[?(@.id==" + jvm.getId() + ")].createdBy", contains("uploadTester"))) + .andExpect(jsonPath("$.content.[?(@.id==" + jvm.getId() + ")].createdAt", contains(jvm.getCreatedAt()))) + .andExpect(jsonPath("$.content.[?(@.id==" + jvm.getId() + ")]._links.type.href", + contains("http://localhost/rest/v1/softwaremoduletypes/" + runtimeType.getId()))) + .andExpect(jsonPath("$.content.[?(@.id==" + jvm.getId() + ")]._links.self.href", + contains("http://localhost/rest/v1/softwaremodules/" + jvm.getId()))) + .andExpect(jsonPath("$.content.[?(@.id==" + jvm.getId() + ")]._links.artifacts.href", + contains("http://localhost/rest/v1/softwaremodules/" + jvm.getId() + "/artifacts"))) + .andExpect(jsonPath("$.content.[?(@.id==" + jvm.getId() + ")]._links.metadata.href", + contains("http://localhost/rest/v1/softwaremodules/" + jvm.getId() + "/metadata?offset=0&limit=50"))) - .andExpect(jsonPath("$content.[?(@.id==" + ah.getId() + ")][0].name", equalTo("name1"))) - .andExpect(jsonPath("$content.[?(@.id==" + ah.getId() + ")][0].version", equalTo("version1"))) - .andExpect(jsonPath("$content.[?(@.id==" + ah.getId() + ")][0].description", equalTo("description1"))) - .andExpect(jsonPath("$content.[?(@.id==" + ah.getId() + ")][0].vendor", equalTo("vendor1"))) - .andExpect(jsonPath("$content.[?(@.id==" + ah.getId() + ")][0].type", equalTo("application"))) - .andExpect(jsonPath("$content.[?(@.id==" + ah.getId() + ")][0].createdBy", equalTo("uploadTester"))) - .andExpect(jsonPath("$content.[?(@.id==" + ah.getId() + ")][0].createdAt", equalTo(ah.getCreatedAt()))) - .andExpect(jsonPath("$content.[?(@.id==" + ah.getId() + ")][0]._links.artifacts.href", - equalTo("http://localhost/rest/v1/softwaremodules/" + ah.getId() + "/artifacts"))) - .andExpect(jsonPath("$content.[?(@.id==" + ah.getId() + ")][0]._links.metadata.href", - equalTo("http://localhost/rest/v1/softwaremodules/" + ah.getId() + .andExpect(jsonPath("$.content.[?(@.id==" + ah.getId() + ")].name", contains("name1"))) + .andExpect(jsonPath("$.content.[?(@.id==" + ah.getId() + ")].version", contains("version1"))) + .andExpect(jsonPath("$.content.[?(@.id==" + ah.getId() + ")].description", contains("description1"))) + .andExpect(jsonPath("$.content.[?(@.id==" + ah.getId() + ")].vendor", contains("vendor1"))) + .andExpect(jsonPath("$.content.[?(@.id==" + ah.getId() + ")].type", contains("application"))) + .andExpect(jsonPath("$.content.[?(@.id==" + ah.getId() + ")].createdBy", contains("uploadTester"))) + .andExpect(jsonPath("$.content.[?(@.id==" + ah.getId() + ")].createdAt", contains(ah.getCreatedAt()))) + .andExpect(jsonPath("$.content.[?(@.id==" + ah.getId() + ")]._links.artifacts.href", + contains("http://localhost/rest/v1/softwaremodules/" + ah.getId() + "/artifacts"))) + .andExpect(jsonPath("$.content.[?(@.id==" + ah.getId() + ")]._links.metadata.href", + contains("http://localhost/rest/v1/softwaremodules/" + ah.getId() + "/metadata?offset=0&limit=50"))) - .andExpect(jsonPath("$content.[?(@.id==" + ah.getId() + ")][0]._links.type.href", - equalTo("http://localhost/rest/v1/softwaremoduletypes/" + appType.getId()))) - .andExpect(jsonPath("$content.[?(@.id==" + ah.getId() + ")][0]._links.self.href", - equalTo("http://localhost/rest/v1/softwaremodules/" + ah.getId()))); + .andExpect(jsonPath("$.content.[?(@.id==" + ah.getId() + ")]._links.type.href", + contains("http://localhost/rest/v1/softwaremoduletypes/" + appType.getId()))) + .andExpect(jsonPath("$.content.[?(@.id==" + ah.getId() + ")]._links.self.href", + contains("http://localhost/rest/v1/softwaremodules/" + ah.getId()))); assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).as("Softwaremodule size is wrong").hasSize(3); } @@ -591,8 +590,8 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW "vendor1"); os1 = softwareManagement.createSoftwareModule(os1); - SoftwareModule jvm1 = entityFactory.generateSoftwareModule(runtimeType, "runtimeName1", "2.0.0", - "description1", "vendor1"); + SoftwareModule jvm1 = entityFactory.generateSoftwareModule(runtimeType, "runtimeName1", "2.0.0", "description1", + "vendor1"); jvm1 = softwareManagement.createSoftwareModule(jvm1); SoftwareModule ah1 = entityFactory.generateSoftwareModule(appType, "appName1", "3.0.0", "description1", @@ -603,8 +602,8 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW "vendor2"); os2 = softwareManagement.createSoftwareModule(os2); - SoftwareModule jvm2 = entityFactory.generateSoftwareModule(runtimeType, "runtimeName2", "2.0.1", - "description2", "vendor2"); + SoftwareModule jvm2 = entityFactory.generateSoftwareModule(runtimeType, "runtimeName2", "2.0.1", "description2", + "vendor2"); jvm2 = softwareManagement.createSoftwareModule(jvm2); SoftwareModule ah2 = entityFactory.generateSoftwareModule(appType, "appName2", "3.0.1", "description2", @@ -617,52 +616,52 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW mvc.perform(get("/rest/v1/softwaremodules?q=name==osName1").accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(jsonPath("$content.[?(@.id==" + os1.getId() + ")][0].name", equalTo("osName1"))) - .andExpect(jsonPath("$content.[?(@.id==" + os1.getId() + ")][0].version", equalTo("1.0.0"))) - .andExpect(jsonPath("$content.[?(@.id==" + os1.getId() + ")][0].description", equalTo("description1"))) - .andExpect(jsonPath("$content.[?(@.id==" + os1.getId() + ")][0].vendor", equalTo("vendor1"))) - .andExpect(jsonPath("$content.[?(@.id==" + os1.getId() + ")][0].type", equalTo("os"))) - .andExpect(jsonPath("$content", hasSize(1))).andExpect(jsonPath("$total", equalTo(1))); + .andExpect(jsonPath("$.content.[?(@.id==" + os1.getId() + ")].name", contains("osName1"))) + .andExpect(jsonPath("$.content.[?(@.id==" + os1.getId() + ")].version", contains("1.0.0"))) + .andExpect(jsonPath("$.content.[?(@.id==" + os1.getId() + ")].description", contains("description1"))) + .andExpect(jsonPath("$.content.[?(@.id==" + os1.getId() + ")].vendor", contains("vendor1"))) + .andExpect(jsonPath("$.content.[?(@.id==" + os1.getId() + ")].type", contains("os"))) + .andExpect(jsonPath("$.content", hasSize(1))).andExpect(jsonPath("$.total", equalTo(1))); // by type, 2 software modules per type exists mvc.perform(get("/rest/v1/softwaremodules?q=type==application").accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(jsonPath("$content.[?(@.id==" + ah1.getId() + ")][0].name", equalTo("appName1"))) - .andExpect(jsonPath("$content.[?(@.id==" + ah1.getId() + ")][0].version", equalTo("3.0.0"))) - .andExpect(jsonPath("$content.[?(@.id==" + ah1.getId() + ")][0].description", equalTo("description1"))) - .andExpect(jsonPath("$content.[?(@.id==" + ah1.getId() + ")][0].vendor", equalTo("vendor1"))) - .andExpect(jsonPath("$content.[?(@.id==" + ah1.getId() + ")][0].type", equalTo("application"))) - .andExpect(jsonPath("$content.[?(@.id==" + ah2.getId() + ")][0].name", equalTo("appName2"))) - .andExpect(jsonPath("$content.[?(@.id==" + ah2.getId() + ")][0].version", equalTo("3.0.1"))) - .andExpect(jsonPath("$content.[?(@.id==" + ah2.getId() + ")][0].description", equalTo("description2"))) - .andExpect(jsonPath("$content.[?(@.id==" + ah2.getId() + ")][0].vendor", equalTo("vendor2"))) - .andExpect(jsonPath("$content.[?(@.id==" + ah2.getId() + ")][0].type", equalTo("application"))) - .andExpect(jsonPath("$content", hasSize(2))).andExpect(jsonPath("$total", equalTo(2))); + .andExpect(jsonPath("$.content.[?(@.id==" + ah1.getId() + ")].name", contains("appName1"))) + .andExpect(jsonPath("$.content.[?(@.id==" + ah1.getId() + ")].version", contains("3.0.0"))) + .andExpect(jsonPath("$.content.[?(@.id==" + ah1.getId() + ")].description", contains("description1"))) + .andExpect(jsonPath("$.content.[?(@.id==" + ah1.getId() + ")].vendor", contains("vendor1"))) + .andExpect(jsonPath("$.content.[?(@.id==" + ah1.getId() + ")].type", contains("application"))) + .andExpect(jsonPath("$.content.[?(@.id==" + ah2.getId() + ")].name", contains("appName2"))) + .andExpect(jsonPath("$.content.[?(@.id==" + ah2.getId() + ")].version", contains("3.0.1"))) + .andExpect(jsonPath("$.content.[?(@.id==" + ah2.getId() + ")].description", contains("description2"))) + .andExpect(jsonPath("$.content.[?(@.id==" + ah2.getId() + ")].vendor", contains("vendor2"))) + .andExpect(jsonPath("$.content.[?(@.id==" + ah2.getId() + ")].type", contains("application"))) + .andExpect(jsonPath("$.content", hasSize(2))).andExpect(jsonPath("$.total", equalTo(2))); // by type and version=2.0.0 -> only one result mvc.perform(get("/rest/v1/softwaremodules?q=type==runtime;version==2.0.0").accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(jsonPath("$content.[?(@.id==" + jvm1.getId() + ")][0].name", equalTo("runtimeName1"))) - .andExpect(jsonPath("$content.[?(@.id==" + jvm1.getId() + ")][0].version", equalTo("2.0.0"))) - .andExpect(jsonPath("$content.[?(@.id==" + jvm1.getId() + ")][0].description", equalTo("description1"))) - .andExpect(jsonPath("$content.[?(@.id==" + jvm1.getId() + ")][0].vendor", equalTo("vendor1"))) - .andExpect(jsonPath("$content", hasSize(1))).andExpect(jsonPath("$total", equalTo(1))); + .andExpect(jsonPath("$.content.[?(@.id==" + jvm1.getId() + ")].name", contains("runtimeName1"))) + .andExpect(jsonPath("$.content.[?(@.id==" + jvm1.getId() + ")].version", contains("2.0.0"))) + .andExpect(jsonPath("$.content.[?(@.id==" + jvm1.getId() + ")].description", contains("description1"))) + .andExpect(jsonPath("$.content.[?(@.id==" + jvm1.getId() + ")].vendor", contains("vendor1"))) + .andExpect(jsonPath("$.content", hasSize(1))).andExpect(jsonPath("$.total", equalTo(1))); // by type and version range >=2.0.0 -> 2 result mvc.perform(get("/rest/v1/softwaremodules?q=type==runtime;version=ge=2.0.0").accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(jsonPath("$content.[?(@.id==" + jvm1.getId() + ")][0].name", equalTo("runtimeName1"))) - .andExpect(jsonPath("$content.[?(@.id==" + jvm1.getId() + ")][0].version", equalTo("2.0.0"))) - .andExpect(jsonPath("$content.[?(@.id==" + jvm1.getId() + ")][0].description", equalTo("description1"))) - .andExpect(jsonPath("$content.[?(@.id==" + jvm1.getId() + ")][0].vendor", equalTo("vendor1"))) - .andExpect(jsonPath("$content.[?(@.id==" + jvm2.getId() + ")][0].name", equalTo("runtimeName2"))) - .andExpect(jsonPath("$content.[?(@.id==" + jvm2.getId() + ")][0].version", equalTo("2.0.1"))) - .andExpect(jsonPath("$content.[?(@.id==" + jvm2.getId() + ")][0].description", equalTo("description2"))) - .andExpect(jsonPath("$content.[?(@.id==" + jvm2.getId() + ")][0].vendor", equalTo("vendor2"))) - .andExpect(jsonPath("$content", hasSize(2))).andExpect(jsonPath("$total", equalTo(2))); + .andExpect(jsonPath("$.content.[?(@.id==" + jvm1.getId() + ")].name", contains("runtimeName1"))) + .andExpect(jsonPath("$.content.[?(@.id==" + jvm1.getId() + ")].version", contains("2.0.0"))) + .andExpect(jsonPath("$.content.[?(@.id==" + jvm1.getId() + ")].description", contains("description1"))) + .andExpect(jsonPath("$.content.[?(@.id==" + jvm1.getId() + ")].vendor", contains("vendor1"))) + .andExpect(jsonPath("$.content.[?(@.id==" + jvm2.getId() + ")].name", contains("runtimeName2"))) + .andExpect(jsonPath("$.content.[?(@.id==" + jvm2.getId() + ")].version", contains("2.0.1"))) + .andExpect(jsonPath("$.content.[?(@.id==" + jvm2.getId() + ")].description", contains("description2"))) + .andExpect(jsonPath("$.content.[?(@.id==" + jvm2.getId() + ")].vendor", contains("vendor2"))) + .andExpect(jsonPath("$.content", hasSize(2))).andExpect(jsonPath("$.total", equalTo(2))); } @Test @@ -670,7 +669,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW public void getSoftwareModulesWithSyntaxErrorFilterParameter() throws Exception { mvc.perform(get("/rest/v1/softwaremodules?q=wrongFIQLSyntax").accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isBadRequest()) - .andExpect(jsonPath("$errorCode", equalTo("hawkbit.server.error.rest.param.rsqlParamSyntax"))); + .andExpect(jsonPath("$.errorCode", equalTo("hawkbit.server.error.rest.param.rsqlParamSyntax"))); } @Test @@ -678,7 +677,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW public void getSoftwareModulesWithUnknownFieldErrorFilterParameter() throws Exception { mvc.perform(get("/rest/v1/softwaremodules?q=wrongField==abc").accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isBadRequest()) - .andExpect(jsonPath("$errorCode", equalTo("hawkbit.server.error.rest.param.rsqlInvalidField"))); + .andExpect(jsonPath("$.errorCode", equalTo("hawkbit.server.error.rest.param.rsqlInvalidField"))); } @Test @@ -692,17 +691,17 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW mvc.perform(get("/rest/v1/softwaremodules/{smId}", os.getId()).accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(jsonPath("$name", equalTo("name1"))).andExpect(jsonPath("$version", equalTo("version1"))) - .andExpect(jsonPath("$description", equalTo("description1"))) - .andExpect(jsonPath("$vendor", equalTo("vendor1"))).andExpect(jsonPath("$type", equalTo("os"))) - .andExpect(jsonPath("$createdBy", equalTo("uploadTester"))) - .andExpect(jsonPath("$createdAt", equalTo(os.getCreatedAt()))) - .andExpect(jsonPath("$_links.metadata.href", + .andExpect(jsonPath("$.name", equalTo("name1"))).andExpect(jsonPath("$.version", equalTo("version1"))) + .andExpect(jsonPath("$.description", equalTo("description1"))) + .andExpect(jsonPath("$.vendor", equalTo("vendor1"))).andExpect(jsonPath("$.type", equalTo("os"))) + .andExpect(jsonPath("$.createdBy", equalTo("uploadTester"))) + .andExpect(jsonPath("$.createdAt", equalTo(os.getCreatedAt()))) + .andExpect(jsonPath("$._links.metadata.href", equalTo("http://localhost/rest/v1/softwaremodules/" + os.getId() + "/metadata?offset=0&limit=50"))) - .andExpect(jsonPath("$_links.type.href", + .andExpect(jsonPath("$._links.type.href", equalTo("http://localhost/rest/v1/softwaremoduletypes/" + osType.getId()))) - .andExpect(jsonPath("$_links.artifacts.href", + .andExpect(jsonPath("$._links.artifacts.href", equalTo("http://localhost/rest/v1/softwaremodules/" + os.getId() + "/artifacts"))); SoftwareModule jvm = entityFactory.generateSoftwareModule(runtimeType, "name1", "version1", "description1", @@ -712,17 +711,17 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW mvc.perform(get("/rest/v1/softwaremodules/{smId}", jvm.getId()).accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(jsonPath("$name", equalTo("name1"))).andExpect(jsonPath("$version", equalTo("version1"))) - .andExpect(jsonPath("$description", equalTo("description1"))) - .andExpect(jsonPath("$vendor", equalTo("vendor1"))).andExpect(jsonPath("$type", equalTo("runtime"))) - .andExpect(jsonPath("$createdBy", equalTo("uploadTester"))) - .andExpect(jsonPath("$createdAt", equalTo(jvm.getCreatedAt()))) - .andExpect(jsonPath("$_links.metadata.href", + .andExpect(jsonPath("$.name", equalTo("name1"))).andExpect(jsonPath("$.version", equalTo("version1"))) + .andExpect(jsonPath("$.description", equalTo("description1"))) + .andExpect(jsonPath("$.vendor", equalTo("vendor1"))).andExpect(jsonPath("$.type", equalTo("runtime"))) + .andExpect(jsonPath("$.createdBy", equalTo("uploadTester"))) + .andExpect(jsonPath("$.createdAt", equalTo(jvm.getCreatedAt()))) + .andExpect(jsonPath("$._links.metadata.href", equalTo("http://localhost/rest/v1/softwaremodules/" + jvm.getId() + "/metadata?offset=0&limit=50"))) - .andExpect(jsonPath("$_links.type.href", + .andExpect(jsonPath("$._links.type.href", equalTo("http://localhost/rest/v1/softwaremoduletypes/" + runtimeType.getId()))) - .andExpect(jsonPath("$_links.artifacts.href", + .andExpect(jsonPath("$._links.artifacts.href", equalTo("http://localhost/rest/v1/softwaremodules/" + jvm.getId() + "/artifacts"))); SoftwareModule ah = entityFactory.generateSoftwareModule(appType, "name1", "version1", "description1", @@ -732,17 +731,18 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW mvc.perform(get("/rest/v1/softwaremodules/{smId}", ah.getId()).accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(jsonPath("$name", equalTo("name1"))).andExpect(jsonPath("$version", equalTo("version1"))) - .andExpect(jsonPath("$description", equalTo("description1"))) - .andExpect(jsonPath("$vendor", equalTo("vendor1"))).andExpect(jsonPath("$type", equalTo("application"))) - .andExpect(jsonPath("$createdBy", equalTo("uploadTester"))) - .andExpect(jsonPath("$createdAt", equalTo(ah.getCreatedAt()))) - .andExpect(jsonPath("$_links.metadata.href", + .andExpect(jsonPath("$.name", equalTo("name1"))).andExpect(jsonPath("$.version", equalTo("version1"))) + .andExpect(jsonPath("$.description", equalTo("description1"))) + .andExpect(jsonPath("$.vendor", equalTo("vendor1"))) + .andExpect(jsonPath("$.type", equalTo("application"))) + .andExpect(jsonPath("$.createdBy", equalTo("uploadTester"))) + .andExpect(jsonPath("$.createdAt", equalTo(ah.getCreatedAt()))) + .andExpect(jsonPath("$._links.metadata.href", equalTo("http://localhost/rest/v1/softwaremodules/" + ah.getId() + "/metadata?offset=0&limit=50"))) - .andExpect(jsonPath("$_links.type.href", + .andExpect(jsonPath("$._links.type.href", equalTo("http://localhost/rest/v1/softwaremoduletypes/" + appType.getId()))) - .andExpect(jsonPath("$_links.artifacts.href", + .andExpect(jsonPath("$._links.artifacts.href", equalTo("http://localhost/rest/v1/softwaremodules/" + ah.getId() + "/artifacts"))); assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).as("Softwaremodule size is wrong").hasSize(3); @@ -756,8 +756,8 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW "vendor1"); final SoftwareModule jvm = entityFactory.generateSoftwareModule(runtimeType, "name2", "version1", "description1", "vendor1"); - final SoftwareModule ah = entityFactory.generateSoftwareModule(appType, "name3", "version1", - "description1", "vendor1"); + final SoftwareModule ah = entityFactory.generateSoftwareModule(appType, "name3", "version1", "description1", + "vendor1"); final List modules = new ArrayList<>(); modules.add(os); @@ -924,8 +924,8 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW final String knownKey2 = "knownKey1"; final String knownValue2 = "knownValue1"; - final SoftwareModule sm = softwareManagement.createSoftwareModule( - entityFactory.generateSoftwareModule(osType, "name 1", "version 1", null, null)); + final SoftwareModule sm = softwareManagement + .createSoftwareModule(entityFactory.generateSoftwareModule(osType, "name 1", "version 1", null, null)); final JSONArray jsonArray = new JSONArray(); jsonArray.put(new JSONObject().put("key", knownKey1).put("value", knownValue1)); @@ -953,10 +953,10 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW final String knownValue = "knownValue"; final String updateValue = "valueForUpdate"; - final SoftwareModule sm = softwareManagement.createSoftwareModule( - entityFactory.generateSoftwareModule(osType, "name 1", "version 1", null, null)); - softwareManagement.createSoftwareModuleMetadata( - entityFactory.generateSoftwareModuleMetadata(sm, knownKey, knownValue)); + final SoftwareModule sm = softwareManagement + .createSoftwareModule(entityFactory.generateSoftwareModule(osType, "name 1", "version 1", null, null)); + softwareManagement + .createSoftwareModuleMetadata(entityFactory.generateSoftwareModuleMetadata(sm, knownKey, knownValue)); final JSONObject jsonObject = new JSONObject().put("key", knownKey).put("value", updateValue); @@ -977,10 +977,10 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW final String knownKey = "knownKey"; final String knownValue = "knownValue"; - final SoftwareModule sm = softwareManagement.createSoftwareModule( - entityFactory.generateSoftwareModule(osType, "name 1", "version 1", null, null)); - softwareManagement.createSoftwareModuleMetadata( - entityFactory.generateSoftwareModuleMetadata(sm, knownKey, knownValue)); + final SoftwareModule sm = softwareManagement + .createSoftwareModule(entityFactory.generateSoftwareModule(osType, "name 1", "version 1", null, null)); + softwareManagement + .createSoftwareModuleMetadata(entityFactory.generateSoftwareModuleMetadata(sm, knownKey, knownValue)); mvc.perform(delete("/rest/v1/softwaremodules/{swId}/metadata/{key}", sm.getId(), knownKey)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); @@ -999,13 +999,13 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW final int totalMetadata = 10; final String knownKeyPrefix = "knownKey"; final String knownValuePrefix = "knownValue"; - final SoftwareModule sm = softwareManagement.createSoftwareModule( - entityFactory.generateSoftwareModule(osType, "name 1", "version 1", null, null)); + final SoftwareModule sm = softwareManagement + .createSoftwareModule(entityFactory.generateSoftwareModule(osType, "name 1", "version 1", null, null)); for (int index = 0; index < totalMetadata; index++) { - softwareManagement.createSoftwareModuleMetadata(entityFactory.generateSoftwareModuleMetadata( - softwareManagement.findSoftwareModuleById(sm.getId()), knownKeyPrefix + index, - knownValuePrefix + index)); + softwareManagement.createSoftwareModuleMetadata( + entityFactory.generateSoftwareModuleMetadata(softwareManagement.findSoftwareModuleById(sm.getId()), + knownKeyPrefix + index, knownValuePrefix + index)); } final String rsqlSearchValue1 = "value==knownValue1"; diff --git a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeResourceTest.java b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeResourceTest.java index 36d975138..a598402cb 100644 --- a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeResourceTest.java +++ b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeResourceTest.java @@ -11,6 +11,7 @@ package org.eclipse.hawkbit.mgmt.rest.resource; import static org.fest.assertions.api.Assertions.assertThat; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.not; +import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.hasSize; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; @@ -62,35 +63,34 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractRestIntegrationT mvc.perform(get("/rest/v1/softwaremoduletypes").accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(jsonPath("$content.[?(@.key==" + osType.getKey() + ")][0].name", equalTo(osType.getName()))) - .andExpect(jsonPath("$content.[?(@.key==" + osType.getKey() + ")][0].description", - equalTo(osType.getDescription()))) - .andExpect(jsonPath("$content.[?(@.key==" + osType.getKey() + ")][0].maxAssignments", equalTo(1))) - .andExpect(jsonPath("$content.[?(@.key==" + osType.getKey() + ")][0].key", equalTo("os"))) - .andExpect(jsonPath("$content.[?(@.key==" + runtimeType.getKey() + ")][0].name", - equalTo(runtimeType.getName()))) - .andExpect(jsonPath("$content.[?(@.key==" + runtimeType.getKey() + ")][0].description", - equalTo(runtimeType.getDescription()))) - .andExpect(jsonPath("$content.[?(@.key==" + runtimeType.getKey() + ")][0].maxAssignments", equalTo(1))) - .andExpect(jsonPath("$content.[?(@.key==" + runtimeType.getKey() + ")][0].key", equalTo("runtime"))) - .andExpect( - jsonPath("$content.[?(@.key==" + appType.getKey() + ")][0].name", equalTo(appType.getName()))) - .andExpect(jsonPath("$content.[?(@.key==" + appType.getKey() + ")][0].description", - equalTo(appType.getDescription()))) - .andExpect(jsonPath("$content.[?(@.key==" + appType.getKey() + ")][0].maxAssignments", - equalTo(Integer.MAX_VALUE))) - .andExpect(jsonPath("$content.[?(@.key==" + appType.getKey() + ")][0].key", equalTo("application"))) - .andExpect(jsonPath("$content.[?(@.key==test123)][0].id", equalTo(testType.getId().intValue()))) - .andExpect(jsonPath("$content.[?(@.key==test123)][0].name", equalTo("TestName123"))) - .andExpect(jsonPath("$content.[?(@.key==test123)][0].description", equalTo("Desc1234"))) - .andExpect(jsonPath("$content.[?(@.key==test123)][0].createdBy", equalTo("uploadTester"))) - .andExpect(jsonPath("$content.[?(@.key==test123)][0].createdAt", equalTo(testType.getCreatedAt()))) - .andExpect(jsonPath("$content.[?(@.key==test123)][0].lastModifiedBy", equalTo("uploadTester"))) - .andExpect(jsonPath("$content.[?(@.key==test123)][0].lastModifiedAt", - equalTo(testType.getLastModifiedAt()))) - .andExpect(jsonPath("$content.[?(@.key==test123)][0].maxAssignments", equalTo(5))) - .andExpect(jsonPath("$content.[?(@.key==test123)][0].key", equalTo("test123"))) - .andExpect(jsonPath("$total", equalTo(4))); + .andExpect(jsonPath("$.content.[?(@.key==" + osType.getKey() + ")].name", contains(osType.getName()))) + .andExpect(jsonPath("$.content.[?(@.key==" + osType.getKey() + ")].description", + contains(osType.getDescription()))) + .andExpect(jsonPath("$.content.[?(@.key==" + osType.getKey() + ")].maxAssignments", contains(1))) + .andExpect(jsonPath("$.content.[?(@.key==" + osType.getKey() + ")].key", contains("os"))) + .andExpect(jsonPath("$.content.[?(@.key==" + runtimeType.getKey() + ")].name", + contains(runtimeType.getName()))) + .andExpect(jsonPath("$.content.[?(@.key==" + runtimeType.getKey() + ")].description", + contains(runtimeType.getDescription()))) + .andExpect(jsonPath("$.content.[?(@.key==" + runtimeType.getKey() + ")].maxAssignments", contains(1))) + .andExpect(jsonPath("$.content.[?(@.key==" + runtimeType.getKey() + ")].key", contains("runtime"))) + .andExpect(jsonPath("$.content.[?(@.key==" + appType.getKey() + ")].name", contains(appType.getName()))) + .andExpect(jsonPath("$.content.[?(@.key==" + appType.getKey() + ")].description", + contains(appType.getDescription()))) + .andExpect(jsonPath("$.content.[?(@.key==" + appType.getKey() + ")].maxAssignments", + contains(Integer.MAX_VALUE))) + .andExpect(jsonPath("$.content.[?(@.key==" + appType.getKey() + ")].key", contains("application"))) + .andExpect(jsonPath("$.content.[?(@.key==test123)].id", contains(testType.getId().intValue()))) + .andExpect(jsonPath("$.content.[?(@.key==test123)].name", contains("TestName123"))) + .andExpect(jsonPath("$.content.[?(@.key==test123)].description", contains("Desc1234"))) + .andExpect(jsonPath("$.content.[?(@.key==test123)].createdBy", contains("uploadTester"))) + .andExpect(jsonPath("$.content.[?(@.key==test123)].createdAt", contains(testType.getCreatedAt()))) + .andExpect(jsonPath("$.content.[?(@.key==test123)].lastModifiedBy", contains("uploadTester"))) + .andExpect(jsonPath("$.content.[?(@.key==test123)].lastModifiedAt", + contains(testType.getLastModifiedAt()))) + .andExpect(jsonPath("$.content.[?(@.key==test123)].maxAssignments", contains(5))) + .andExpect(jsonPath("$.content.[?(@.key==test123)].key", contains("test123"))) + .andExpect(jsonPath("$.total", equalTo(4))); } @Test @@ -107,30 +107,32 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractRestIntegrationT .param(MgmtRestConstants.REQUEST_PARAMETER_SORTING, "MAXASSIGNMENTS:DESC")) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(jsonPath("$content.[1].id", equalTo(testType.getId().intValue()))) - .andExpect(jsonPath("$content.[1].name", equalTo("TestName123"))) - .andExpect(jsonPath("$content.[1].description", equalTo("Desc1234"))) - .andExpect(jsonPath("$content.[1].createdBy", equalTo("uploadTester"))) - .andExpect(jsonPath("$content.[1].createdAt", equalTo(testType.getCreatedAt()))) - .andExpect(jsonPath("$content.[1].lastModifiedBy", equalTo("uploadTester"))) - .andExpect(jsonPath("$content.[1].lastModifiedAt", equalTo(testType.getLastModifiedAt()))) - .andExpect(jsonPath("$content.[1].maxAssignments", equalTo(5))) - .andExpect(jsonPath("$content.[1].key", equalTo("test123"))).andExpect(jsonPath("$total", equalTo(4))); + .andExpect(jsonPath("$.content.[1].id", equalTo(testType.getId().intValue()))) + .andExpect(jsonPath("$.content.[1].name", equalTo("TestName123"))) + .andExpect(jsonPath("$.content.[1].description", equalTo("Desc1234"))) + .andExpect(jsonPath("$.content.[1].createdBy", equalTo("uploadTester"))) + .andExpect(jsonPath("$.content.[1].createdAt", equalTo(testType.getCreatedAt()))) + .andExpect(jsonPath("$.content.[1].lastModifiedBy", equalTo("uploadTester"))) + .andExpect(jsonPath("$.content.[1].lastModifiedAt", equalTo(testType.getLastModifiedAt()))) + .andExpect(jsonPath("$.content.[1].maxAssignments", equalTo(5))) + .andExpect(jsonPath("$.content.[1].key", equalTo("test123"))) + .andExpect(jsonPath("$.total", equalTo(4))); // ascending mvc.perform(get("/rest/v1/softwaremoduletypes").accept(MediaType.APPLICATION_JSON) .param(MgmtRestConstants.REQUEST_PARAMETER_SORTING, "MAXASSIGNMENTS:ASC")) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(jsonPath("$content.[2].id", equalTo(testType.getId().intValue()))) - .andExpect(jsonPath("$content.[2].name", equalTo("TestName123"))) - .andExpect(jsonPath("$content.[2].description", equalTo("Desc1234"))) - .andExpect(jsonPath("$content.[2].createdBy", equalTo("uploadTester"))) - .andExpect(jsonPath("$content.[2].createdAt", equalTo(testType.getCreatedAt()))) - .andExpect(jsonPath("$content.[2].lastModifiedBy", equalTo("uploadTester"))) - .andExpect(jsonPath("$content.[2].lastModifiedAt", equalTo(testType.getLastModifiedAt()))) - .andExpect(jsonPath("$content.[2].maxAssignments", equalTo(5))) - .andExpect(jsonPath("$content.[2].key", equalTo("test123"))).andExpect(jsonPath("$total", equalTo(4))); + .andExpect(jsonPath("$.content.[2].id", equalTo(testType.getId().intValue()))) + .andExpect(jsonPath("$.content.[2].name", equalTo("TestName123"))) + .andExpect(jsonPath("$.content.[2].description", equalTo("Desc1234"))) + .andExpect(jsonPath("$.content.[2].createdBy", equalTo("uploadTester"))) + .andExpect(jsonPath("$.content.[2].createdAt", equalTo(testType.getCreatedAt()))) + .andExpect(jsonPath("$.content.[2].lastModifiedBy", equalTo("uploadTester"))) + .andExpect(jsonPath("$.content.[2].lastModifiedAt", equalTo(testType.getLastModifiedAt()))) + .andExpect(jsonPath("$.content.[2].maxAssignments", equalTo(5))) + .andExpect(jsonPath("$.content.[2].key", equalTo("test123"))) + .andExpect(jsonPath("$.total", equalTo(4))); } @Test @@ -191,13 +193,13 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractRestIntegrationT mvc.perform(get("/rest/v1/softwaremoduletypes/{smtId}", testType.getId()).accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(jsonPath("$name", equalTo("TestName123"))) - .andExpect(jsonPath("$description", equalTo("Desc1234"))) - .andExpect(jsonPath("$maxAssignments", equalTo(5))) - .andExpect(jsonPath("$createdBy", equalTo("uploadTester"))) - .andExpect(jsonPath("$createdAt", equalTo(testType.getCreatedAt()))) - .andExpect(jsonPath("$lastModifiedBy", equalTo("uploadTester"))) - .andExpect(jsonPath("$lastModifiedAt", equalTo(testType.getLastModifiedAt()))); + .andExpect(jsonPath("$.name", equalTo("TestName123"))) + .andExpect(jsonPath("$.description", equalTo("Desc1234"))) + .andExpect(jsonPath("$.maxAssignments", equalTo(5))) + .andExpect(jsonPath("$.createdBy", equalTo("uploadTester"))) + .andExpect(jsonPath("$.createdAt", equalTo(testType.getCreatedAt()))) + .andExpect(jsonPath("$.lastModifiedBy", equalTo("uploadTester"))) + .andExpect(jsonPath("$.lastModifiedAt", equalTo(testType.getLastModifiedAt()))); } @Test @@ -243,9 +245,9 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractRestIntegrationT mvc.perform(put("/rest/v1/softwaremoduletypes/{smId}", testType.getId()).content(body) .contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) - .andExpect(jsonPath("$id", equalTo(testType.getId().intValue()))) - .andExpect(jsonPath("$description", equalTo("foobardesc"))) - .andExpect(jsonPath("$name", equalTo("TestName123"))).andReturn(); + .andExpect(jsonPath("$.id", equalTo(testType.getId().intValue()))) + .andExpect(jsonPath("$.description", equalTo("foobardesc"))) + .andExpect(jsonPath("$.name", equalTo("TestName123"))).andReturn(); } diff --git a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResourceTest.java b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResourceTest.java index 8edb6aa86..e804dcb1f 100644 --- a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResourceTest.java +++ b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResourceTest.java @@ -12,6 +12,7 @@ import static com.google.common.collect.Lists.newArrayList; import static org.fest.assertions.api.Assertions.assertThat; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.not; +import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.hasItem; import static org.hamcrest.Matchers.hasKey; import static org.hamcrest.Matchers.hasSize; @@ -139,10 +140,10 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest { public void securityTokenIsNotInResponseIfMissingPermission() throws Exception { final String knownControllerId = "knownControllerId"; - final Target createTarget = targetManagement.createTarget(entityFactory.generateTarget(knownControllerId)); + targetManagement.createTarget(entityFactory.generateTarget(knownControllerId)); mvc.perform(get(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/{targetId}", knownControllerId)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) - .andExpect(jsonPath("securityToken", equalTo(null))); + .andExpect(jsonPath("securityToken").doesNotExist()); } @Test @@ -172,14 +173,14 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest { mvc.perform(get(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING)).andDo(MockMvcResultPrinter.print()) .andExpect(status().isOk()).andExpect(jsonPath("total", equalTo(2))) .andExpect(jsonPath("size", equalTo(2))) - .andExpect(jsonPath("$content.[?(@.controllerId==" + knownControllerId1 + ")][0].ipAddress", - equalTo("127.0.0.1"))) - .andExpect(jsonPath("$content.[?(@.controllerId==" + knownControllerId2 + ")][0].ipAddress", - equalTo("127.0.0.1"))) - .andExpect(jsonPath("$content.[?(@.controllerId==" + knownControllerId1 + ")][0].address", - equalTo(IpUtil.createHttpUri("127.0.0.1").toString()))) - .andExpect(jsonPath("$content.[?(@.controllerId==" + knownControllerId2 + ")][0].address", - equalTo(IpUtil.createHttpUri("127.0.0.1").toString()))); + .andExpect(jsonPath("$.content.[?(@.controllerId==" + knownControllerId1 + ")].ipAddress", + contains("127.0.0.1"))) + .andExpect(jsonPath("$.content.[?(@.controllerId==" + knownControllerId2 + ")].ipAddress", + contains("127.0.0.1"))) + .andExpect(jsonPath("$.content.[?(@.controllerId==" + knownControllerId1 + ")].address", + contains(IpUtil.createHttpUri("127.0.0.1").toString()))) + .andExpect(jsonPath("$.content.[?(@.controllerId==" + knownControllerId2 + ")].address", + contains(IpUtil.createHttpUri("127.0.0.1").toString()))); } private void createTarget(final String controllerId) { @@ -418,32 +419,32 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest { .andExpect(jsonPath(JSON_PATH_PAGED_LIST_SIZE, equalTo(knownTargetAmount))) .andExpect(jsonPath(JSON_PATH_PAGED_LIST_CONTENT, hasSize(knownTargetAmount))) // idA - .andExpect(jsonPath("$content.[?(@.name==" + idA + ")][0]._links.self.href", - equalTo(linksHrefPrefix + idA))) - .andExpect(jsonPath("$content.[?(@.name==" + idA + ")][0].name", equalTo(idA))) - .andExpect(jsonPath("$content.[?(@.name==" + idA + ")][0].description", equalTo(idA))) - .andExpect(jsonPath("$content.[?(@.name==" + idA + ")][0].controllerId", equalTo(idA))) - .andExpect(jsonPath("$content.[?(@.name==" + idA + ")][0].createdBy", equalTo("bumlux"))) - .andExpect(jsonPath("$content.[?(@.name==" + idA + ")][0].updateStatus", equalTo("unknown"))) - .andExpect(jsonPath("$content.[?(@.name==" + idA + ")][0].lastControllerRequestAt", notNullValue())) + .andExpect(jsonPath("$.content.[?(@.name==" + idA + ")]._links.self.href", + contains(linksHrefPrefix + idA))) + .andExpect(jsonPath("$.content.[?(@.name==" + idA + ")].name", contains(idA))) + .andExpect(jsonPath("$.content.[?(@.name==" + idA + ")].description", contains(idA))) + .andExpect(jsonPath("$.content.[?(@.name==" + idA + ")].controllerId", contains(idA))) + .andExpect(jsonPath("$.content.[?(@.name==" + idA + ")].createdBy", contains("bumlux"))) + .andExpect(jsonPath("$.content.[?(@.name==" + idA + ")].updateStatus", contains("unknown"))) + .andExpect(jsonPath("$.content.[?(@.name==" + idA + ")].lastControllerRequestAt", notNullValue())) // idB - .andExpect(jsonPath("$content.[?(@.name==" + idB + ")][0]._links.self.href", - equalTo(linksHrefPrefix + idB))) - .andExpect(jsonPath("$content.[?(@.name==" + idB + ")][0].name", equalTo(idB))) - .andExpect(jsonPath("$content.[?(@.name==" + idB + ")][0].description", equalTo(idB))) - .andExpect(jsonPath("$content.[?(@.name==" + idB + ")][0].controllerId", equalTo(idB))) - .andExpect(jsonPath("$content.[?(@.name==" + idB + ")][0].createdBy", equalTo("bumlux"))) - .andExpect(jsonPath("$content.[?(@.name==" + idB + ")][0].updateStatus", equalTo("unknown"))) - .andExpect(jsonPath("$content.[?(@.name==" + idA + ")][0].lastControllerRequestAt", notNullValue())) + .andExpect(jsonPath("$.content.[?(@.name==" + idB + ")]._links.self.href", + contains(linksHrefPrefix + idB))) + .andExpect(jsonPath("$.content.[?(@.name==" + idB + ")].name", contains(idB))) + .andExpect(jsonPath("$.content.[?(@.name==" + idB + ")].description", contains(idB))) + .andExpect(jsonPath("$.content.[?(@.name==" + idB + ")].controllerId", contains(idB))) + .andExpect(jsonPath("$.content.[?(@.name==" + idB + ")].createdBy", contains("bumlux"))) + .andExpect(jsonPath("$.content.[?(@.name==" + idB + ")].updateStatus", contains("unknown"))) + .andExpect(jsonPath("$.content.[?(@.name==" + idA + ")].lastControllerRequestAt", notNullValue())) // idC - .andExpect(jsonPath("$content.[?(@.name==" + idC + ")][0]._links.self.href", - equalTo(linksHrefPrefix + idC))) - .andExpect(jsonPath("$content.[?(@.name==" + idC + ")][0].name", equalTo(idC))) - .andExpect(jsonPath("$content.[?(@.name==" + idC + ")][0].description", equalTo(idC))) - .andExpect(jsonPath("$content.[?(@.name==" + idC + ")][0].controllerId", equalTo(idC))) - .andExpect(jsonPath("$content.[?(@.name==" + idC + ")][0].createdBy", equalTo("bumlux"))) - .andExpect(jsonPath("$content.[?(@.name==" + idC + ")][0].updateStatus", equalTo("unknown"))) - .andExpect(jsonPath("$content.[?(@.name==" + idA + ")][0].lastControllerRequestAt", notNullValue())); + .andExpect(jsonPath("$.content.[?(@.name==" + idC + ")]._links.self.href", + contains(linksHrefPrefix + idC))) + .andExpect(jsonPath("$.content.[?(@.name==" + idC + ")].name", contains(idC))) + .andExpect(jsonPath("$.content.[?(@.name==" + idC + ")].description", contains(idC))) + .andExpect(jsonPath("$.content.[?(@.name==" + idC + ")].controllerId", contains(idC))) + .andExpect(jsonPath("$.content.[?(@.name==" + idC + ")].createdBy", contains("bumlux"))) + .andExpect(jsonPath("$.content.[?(@.name==" + idC + ")].updateStatus", contains("unknown"))) + .andExpect(jsonPath("$.content.[?(@.name==" + idA + ")].lastControllerRequestAt", notNullValue())); } @Test @@ -462,13 +463,13 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest { .andExpect(jsonPath(JSON_PATH_PAGED_LIST_SIZE, equalTo(limitSize))) .andExpect(jsonPath(JSON_PATH_PAGED_LIST_CONTENT, hasSize(limitSize))) // idA - .andExpect(jsonPath("$content.[?(@.name==" + idA + ")][0]._links.self.href", - equalTo(linksHrefPrefix + idA))) - .andExpect(jsonPath("$content.[?(@.name==" + idA + ")][0].name", equalTo(idA))) - .andExpect(jsonPath("$content.[?(@.name==" + idA + ")][0].description", equalTo(idA))) - .andExpect(jsonPath("$content.[?(@.name==" + idA + ")][0].controllerId", equalTo(idA))) - .andExpect(jsonPath("$content.[?(@.name==" + idA + ")][0].createdBy", equalTo("bumlux"))) - .andExpect(jsonPath("$content.[?(@.name==" + idA + ")][0].updateStatus", equalTo("unknown"))); + .andExpect(jsonPath("$.content.[?(@.name==" + idA + ")]._links.self.href", + contains(linksHrefPrefix + idA))) + .andExpect(jsonPath("$.content.[?(@.name==" + idA + ")].name", contains(idA))) + .andExpect(jsonPath("$.content.[?(@.name==" + idA + ")].description", contains(idA))) + .andExpect(jsonPath("$.content.[?(@.name==" + idA + ")].controllerId", contains(idA))) + .andExpect(jsonPath("$.content.[?(@.name==" + idA + ")].createdBy", contains("bumlux"))) + .andExpect(jsonPath("$.content.[?(@.name==" + idA + ")].updateStatus", contains("unknown"))); } @Test @@ -491,29 +492,29 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest { .andExpect(jsonPath(JSON_PATH_PAGED_LIST_SIZE, equalTo(expectedSize))) .andExpect(jsonPath(JSON_PATH_PAGED_LIST_CONTENT, hasSize(expectedSize))) // idA - .andExpect(jsonPath("$content.[?(@.name==" + idC + ")][0]._links.self.href", - equalTo(linksHrefPrefix + idC))) - .andExpect(jsonPath("$content.[?(@.name==" + idC + ")][0].name", equalTo(idC))) - .andExpect(jsonPath("$content.[?(@.name==" + idC + ")][0].description", equalTo(idC))) - .andExpect(jsonPath("$content.[?(@.name==" + idC + ")][0].controllerId", equalTo(idC))) - .andExpect(jsonPath("$content.[?(@.name==" + idC + ")][0].createdBy", equalTo("bumlux"))) - .andExpect(jsonPath("$content.[?(@.name==" + idC + ")][0].updateStatus", equalTo("unknown"))) + .andExpect(jsonPath("$.content.[?(@.name==" + idC + ")]._links.self.href", + contains(linksHrefPrefix + idC))) + .andExpect(jsonPath("$.content.[?(@.name==" + idC + ")].name", contains(idC))) + .andExpect(jsonPath("$.content.[?(@.name==" + idC + ")].description", contains(idC))) + .andExpect(jsonPath("$.content.[?(@.name==" + idC + ")].controllerId", contains(idC))) + .andExpect(jsonPath("$.content.[?(@.name==" + idC + ")].createdBy", contains("bumlux"))) + .andExpect(jsonPath("$.content.[?(@.name==" + idC + ")].updateStatus", contains("unknown"))) // idB - .andExpect(jsonPath("$content.[?(@.name==" + idD + ")][0]._links.self.href", - equalTo(linksHrefPrefix + idD))) - .andExpect(jsonPath("$content.[?(@.name==" + idD + ")][0].name", equalTo(idD))) - .andExpect(jsonPath("$content.[?(@.name==" + idD + ")][0].description", equalTo(idD))) - .andExpect(jsonPath("$content.[?(@.name==" + idD + ")][0].controllerId", equalTo(idD))) - .andExpect(jsonPath("$content.[?(@.name==" + idD + ")][0].createdBy", equalTo("bumlux"))) - .andExpect(jsonPath("$content.[?(@.name==" + idD + ")][0].updateStatus", equalTo("unknown"))) + .andExpect(jsonPath("$.content.[?(@.name==" + idD + ")]._links.self.href", + contains(linksHrefPrefix + idD))) + .andExpect(jsonPath("$.content.[?(@.name==" + idD + ")].name", contains(idD))) + .andExpect(jsonPath("$.content.[?(@.name==" + idD + ")].description", contains(idD))) + .andExpect(jsonPath("$.content.[?(@.name==" + idD + ")].controllerId", contains(idD))) + .andExpect(jsonPath("$.content.[?(@.name==" + idD + ")].createdBy", contains("bumlux"))) + .andExpect(jsonPath("$.content.[?(@.name==" + idD + ")].updateStatus", contains("unknown"))) // idC - .andExpect(jsonPath("$content.[?(@.name==" + idE + ")][0]._links.self.href", - equalTo(linksHrefPrefix + idE))) - .andExpect(jsonPath("$content.[?(@.name==" + idE + ")][0].name", equalTo(idE))) - .andExpect(jsonPath("$content.[?(@.name==" + idE + ")][0].description", equalTo(idE))) - .andExpect(jsonPath("$content.[?(@.name==" + idE + ")][0].controllerId", equalTo(idE))) - .andExpect(jsonPath("$content.[?(@.name==" + idE + ")][0].createdBy", equalTo("bumlux"))) - .andExpect(jsonPath("$content.[?(@.name==" + idE + ")][0].updateStatus", equalTo("unknown"))); + .andExpect(jsonPath("$.content.[?(@.name==" + idE + ")]._links.self.href", + contains(linksHrefPrefix + idE))) + .andExpect(jsonPath("$.content.[?(@.name==" + idE + ")].name", contains(idE))) + .andExpect(jsonPath("$.content.[?(@.name==" + idE + ")].description", contains(idE))) + .andExpect(jsonPath("$.content.[?(@.name==" + idE + ")].controllerId", contains(idE))) + .andExpect(jsonPath("$.content.[?(@.name==" + idE + ")].createdBy", contains("bumlux"))) + .andExpect(jsonPath("$.content.[?(@.name==" + idE + ")].updateStatus", contains("unknown"))); } @Test @@ -533,9 +534,9 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest { .andExpect(jsonPath("$.pollStatus", hasKey("lastRequestAt"))) .andExpect(jsonPath("$.pollStatus", hasKey("nextExpectedRequestAt"))) .andExpect(jsonPath("$.pollStatus.overdue", equalTo(false))) - .andExpect(jsonPath("$_links.assignedDS.href", equalTo(hrefPrefix + "assignedDS"))) - .andExpect(jsonPath("$_links.installedDS.href", equalTo(hrefPrefix + "installedDS"))) - .andExpect(jsonPath("$_links.actions.href", + .andExpect(jsonPath("$._links.assignedDS.href", equalTo(hrefPrefix + "assignedDS"))) + .andExpect(jsonPath("$._links.installedDS.href", equalTo(hrefPrefix + "installedDS"))) + .andExpect(jsonPath("$._links.actions.href", equalTo(hrefPrefix + "actions" + "?offset=0&limit=50&sort=id:DESC"))); } @@ -589,37 +590,37 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest { .andExpect(jsonPath(JSON_PATH_DESCRIPTION, equalTo(ds.getDescription()))) // os .andExpect( - jsonPath("$modules.[?(@.type==" + osType.getKey() + ")][0].id", equalTo(os.getId().intValue()))) - .andExpect(jsonPath("$modules.[?(@.type==" + osType.getKey() + ")][0].name", equalTo(os.getName()))) - .andExpect(jsonPath("$modules.[?(@.type==" + osType.getKey() + ")][0].description", - equalTo(os.getDescription()))) + jsonPath("$.modules.[?(@.type==" + osType.getKey() + ")].id", contains(os.getId().intValue()))) + .andExpect(jsonPath("$.modules.[?(@.type==" + osType.getKey() + ")].name", contains(os.getName()))) + .andExpect(jsonPath("$.modules.[?(@.type==" + osType.getKey() + ")].description", + contains(os.getDescription()))) .andExpect( - jsonPath("$modules.[?(@.type==" + osType.getKey() + ")][0].version", equalTo(os.getVersion()))) - .andExpect(jsonPath("$modules.[?(@.type==" + osType.getKey() + ")][0].vendor", equalTo(os.getVendor()))) - .andExpect(jsonPath("$modules.[?(@.type==" + osType.getKey() + ")][0].type", equalTo("os"))) + jsonPath("$.modules.[?(@.type==" + osType.getKey() + ")].version", contains(os.getVersion()))) + .andExpect(jsonPath("$.modules.[?(@.type==" + osType.getKey() + ")].vendor", contains(os.getVendor()))) + .andExpect(jsonPath("$.modules.[?(@.type==" + osType.getKey() + ")].type", contains("os"))) // jvm - .andExpect(jsonPath("$modules.[?(@.type==" + runtimeType.getKey() + ")][0].id", - equalTo(jvm.getId().intValue()))) + .andExpect(jsonPath("$.modules.[?(@.type==" + runtimeType.getKey() + ")].id", + contains(jvm.getId().intValue()))) .andExpect( - jsonPath("$modules.[?(@.type==" + runtimeType.getKey() + ")][0].name", equalTo(jvm.getName()))) - .andExpect(jsonPath("$modules.[?(@.type==" + runtimeType.getKey() + ")][0].description", - equalTo(jvm.getDescription()))) - .andExpect(jsonPath("$modules.[?(@.type==" + runtimeType.getKey() + ")][0].version", - equalTo(jvm.getVersion()))) - .andExpect(jsonPath("$modules.[?(@.type==" + runtimeType.getKey() + ")][0].vendor", - equalTo(jvm.getVendor()))) - .andExpect(jsonPath("$modules.[?(@.type==" + runtimeType.getKey() + ")][0].type", equalTo("runtime"))) + jsonPath("$.modules.[?(@.type==" + runtimeType.getKey() + ")].name", contains(jvm.getName()))) + .andExpect(jsonPath("$.modules.[?(@.type==" + runtimeType.getKey() + ")].description", + contains(jvm.getDescription()))) + .andExpect(jsonPath("$.modules.[?(@.type==" + runtimeType.getKey() + ")].version", + contains(jvm.getVersion()))) + .andExpect(jsonPath("$.modules.[?(@.type==" + runtimeType.getKey() + ")].vendor", + contains(jvm.getVendor()))) + .andExpect(jsonPath("$.modules.[?(@.type==" + runtimeType.getKey() + ")].type", contains("runtime"))) // baseApp - .andExpect(jsonPath("$modules.[?(@.type==" + appType.getKey() + ")][0].id", - equalTo(bApp.getId().intValue()))) - .andExpect(jsonPath("$modules.[?(@.type==" + appType.getKey() + ")][0].name", equalTo(bApp.getName()))) - .andExpect(jsonPath("$modules.[?(@.type==" + appType.getKey() + ")][0].description", - equalTo(bApp.getDescription()))) - .andExpect(jsonPath("$modules.[?(@.type==" + appType.getKey() + ")][0].version", - equalTo(bApp.getVersion()))) + .andExpect(jsonPath("$.modules.[?(@.type==" + appType.getKey() + ")].id", + contains(bApp.getId().intValue()))) + .andExpect(jsonPath("$.modules.[?(@.type==" + appType.getKey() + ")].name", contains(bApp.getName()))) + .andExpect(jsonPath("$.modules.[?(@.type==" + appType.getKey() + ")].description", + contains(bApp.getDescription()))) + .andExpect(jsonPath("$.modules.[?(@.type==" + appType.getKey() + ")].version", + contains(bApp.getVersion()))) .andExpect( - jsonPath("$modules.[?(@.type==" + appType.getKey() + ")][0].vendor", equalTo(bApp.getVendor()))) - .andExpect(jsonPath("$modules.[?(@.type==" + appType.getKey() + ")][0].type", equalTo("application"))); + jsonPath("$.modules.[?(@.type==" + appType.getKey() + ")].vendor", contains(bApp.getVendor()))) + .andExpect(jsonPath("$.modules.[?(@.type==" + appType.getKey() + ")].type", contains("application"))); } diff --git a/pom.xml b/pom.xml index e952f15bd..31a175bd6 100644 --- a/pom.xml +++ b/pom.xml @@ -95,7 +95,6 @@ 2.6.2 1.5.4 1.0.2 - 0.9.1 19.0 1.4.3 1.50.5 @@ -486,12 +485,6 @@ rsql-parser ${rsql-parser.version} - - - com.jayway.jsonpath - json-path - ${json-path.version} - com.googlecode.json-simple json-simple @@ -558,12 +551,6 @@ ${pl.pragmatists.version} test - - com.jayway.jsonpath - json-path-assert - ${json-path.version} - test - org.mariadb.jdbc mariadb-java-client From 12387b7cd1ef0ffa5673139f98684f58a80545e2 Mon Sep 17 00:00:00 2001 From: Michael Hirsch Date: Wed, 31 Aug 2016 08:55:59 +0200 Subject: [PATCH 24/24] remove spaces Signed-off-by: Michael Hirsch --- hawkbit-repository/hawkbit-repository-jpa/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hawkbit-repository/hawkbit-repository-jpa/pom.xml b/hawkbit-repository/hawkbit-repository-jpa/pom.xml index 3646e97fc..3a66a0a9d 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/pom.xml +++ b/hawkbit-repository/hawkbit-repository-jpa/pom.xml @@ -159,7 +159,7 @@ weave - +