Initial check in accordance with Parallel IP

This commit is contained in:
Kai Zimmermann
2016-01-21 13:18:55 +01:00
parent c5e4f1139f
commit 7497ab61ed
763 changed files with 114508 additions and 0 deletions

View File

@@ -0,0 +1,67 @@
/**
* 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.push;
import static org.fest.assertions.api.Assertions.assertThat;
import static org.mockito.Mockito.when;
import javax.servlet.http.HttpSession;
import org.atmosphere.cpr.AtmosphereRequest;
import org.atmosphere.cpr.AtmosphereResource;
import org.junit.After;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.web.context.HttpSessionSecurityContextRepository;
@RunWith(MockitoJUnitRunner.class)
public class SpringSecurityAtmosphereInterceptorTest {
@Mock
private AtmosphereResource atmosphereResourceMock;
@Mock
private AtmosphereRequest atmosphereRequestMock;
@Mock
private SecurityContext sessionSecurityContextMock;
@Mock
private HttpSession httpSessionMock;
private final SpringSecurityAtmosphereInterceptor underTest = new SpringSecurityAtmosphereInterceptor();
@After
public void after() {
SecurityContextHolder.clearContext();
}
@Test
public void inspectRetrievesSetsSecurityContextFromRequestToThreadLocal() {
when(atmosphereResourceMock.getRequest()).thenReturn(atmosphereRequestMock);
when(atmosphereRequestMock.getSession()).thenReturn(httpSessionMock);
when(httpSessionMock.getAttribute(Mockito.eq(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY)))
.thenReturn(sessionSecurityContextMock);
underTest.inspect(atmosphereResourceMock);
// verify
assertThat(SecurityContextHolder.getContext()).isEqualTo(sessionSecurityContextMock);
}
@Test
public void afterAtmosphereRequestSecurityContextGetsCleared() {
SecurityContextHolder.setContext(sessionSecurityContextMock);
underTest.postInspect(atmosphereResourceMock);
assertThat(SecurityContextHolder.getContext()).isNotEqualTo(sessionSecurityContextMock);
}
}

View File

@@ -0,0 +1,64 @@
/**
* 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.ui.utils;
import static org.fest.assertions.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import java.util.concurrent.ThreadFactory;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
@RunWith(MockitoJUnitRunner.class)
public class NamingThreadFactoryTest {
@Mock
private final Runnable runnableMock = mock(Runnable.class);
@Test
public void setsNameForThreads() {
final String knownName = "knownName";
final ThreadFactory threadFactory = new NamingThreadFactory(knownName);
final Thread newThread1 = threadFactory.newThread(runnableMock);
final Thread newThread2 = threadFactory.newThread(runnableMock);
assertThat(newThread1.getName()).isEqualTo(NamingThreadFactory.SP_PREFIX + knownName);
assertThat(newThread2.getName()).isEqualTo(NamingThreadFactory.SP_PREFIX + knownName);
}
@Test
public void setsFormatedNameForThreads() {
final String nameFormat = "knownName-%d";
final String knownName1 = "knownName-0";
final String knownName2 = "knownName-1";
final ThreadFactory threadFactory = new NamingThreadFactory(nameFormat);
final Thread newThread1 = threadFactory.newThread(runnableMock);
final Thread newThread2 = threadFactory.newThread(runnableMock);
assertThat(newThread1.getName()).isEqualTo(NamingThreadFactory.SP_PREFIX + knownName1);
assertThat(newThread2.getName()).isEqualTo(NamingThreadFactory.SP_PREFIX + knownName2);
}
@Test
public void setsRunnableForThreads() {
final String knownName = "knownName";
final ThreadFactory threadFactory = new NamingThreadFactory(knownName);
final Thread newThread1 = threadFactory.newThread(runnableMock);
final Thread newThread2 = threadFactory.newThread(runnableMock);
newThread1.run();
newThread2.run();
verify(runnableMock, times(2)).run();
}
}

View File

@@ -0,0 +1,64 @@
/**
* 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.ui.utils;
import static org.fest.assertions.api.Assertions.assertThat;
import org.eclipse.hawkbit.ui.components.SPUIButton;
import org.eclipse.hawkbit.ui.components.SPUIComponentProvider;
import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleSmallNoBorderUH;
import org.junit.Test;
import com.vaadin.shared.ui.label.ContentMode;
import com.vaadin.ui.Button;
import com.vaadin.ui.Label;
/**
* Unit Test block for UI Component provider. Dynamic Factory Testing.
*
*
*
*/
public class SPUIComponentProviderTest {
/**
* Test case for check button factory.
*
* @throws Exception
*/
@Test
public void checkButtonFactory() throws Exception {
// Checking Dyanmic Factory
Button placeHolderButton = null;
placeHolderButton = SPUIComponentProvider.getButton("", "Test", "Test",
SPUIButtonDefinitions.SP_BUTTON_STATUS_STYLE, true, null, SPUIButtonStyleSmallNoBorderUH.class);
assertThat(placeHolderButton).isInstanceOf(SPUIButton.class);
assertThat(placeHolderButton.getCaption()).isEqualTo("Test");
assertThat(placeHolderButton.getStyleName()).isEqualTo(SPUIButtonDefinitions.SP_BUTTON_STATUS_STYLE);
}
/**
* Test case for check Label factory.
*
* @throws Exception
*/
@Test
public void checkLabelFactory() throws Exception {
Label placeHolderLabel = null;
placeHolderLabel = SPUIComponentProvider.getLabel("TestTable", SPUILabelDefinitions.SP_WIDGET_CAPTION);
assertThat(placeHolderLabel).isInstanceOf(Label.class);
assertThat(placeHolderLabel.getValue()).isEqualTo("TestTable");
assertThat(placeHolderLabel.getContentMode()).isNotEqualTo(ContentMode.HTML);
placeHolderLabel = SPUIComponentProvider.getLabel("TestMSG", SPUILabelDefinitions.SP_LABEL_MESSAGE);
assertThat(placeHolderLabel.getValue()).isEqualTo("TestMSG");
assertThat(placeHolderLabel.getContentMode()).isEqualTo(ContentMode.HTML);
}
}