165 changed files with 9510 additions and 363 deletions
@ -1,43 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2022 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
package org.thingsboard.server.dao.entity; |
|||
|
|||
import org.apache.commons.text.CaseUtils; |
|||
import org.springframework.beans.factory.BeanFactory; |
|||
import org.springframework.stereotype.Service; |
|||
import org.thingsboard.server.common.data.EntityType; |
|||
|
|||
@Service |
|||
public class EntityServiceBeanFactory { |
|||
|
|||
private static final String SERVICE_SUFFIX = "DaoService"; |
|||
|
|||
private final BeanFactory beanFactory; |
|||
|
|||
public EntityServiceBeanFactory(BeanFactory beanFactory) { |
|||
this.beanFactory = beanFactory; |
|||
} |
|||
|
|||
public TbEntityService getServiceByEntityType(EntityType entityType) { |
|||
String beanName = EntityType.RULE_NODE.equals(entityType) ? getBeanName(EntityType.RULE_CHAIN) : getBeanName(entityType); |
|||
return beanFactory.getBean(beanName, TbEntityService.class); |
|||
} |
|||
|
|||
private String getBeanName(EntityType entityType) { |
|||
return CaseUtils.toCamelCase(entityType.name(), true, '_') + SERVICE_SUFFIX; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,24 @@ |
|||
/** |
|||
* Copyright © 2016-2022 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
package org.thingsboard.server.dao.entity; |
|||
|
|||
import org.thingsboard.server.common.data.EntityType; |
|||
|
|||
public interface EntityServiceRegistry { |
|||
|
|||
EntityDaoService getServiceByEntityType(EntityType entityType); |
|||
|
|||
} |
|||
@ -0,0 +1,31 @@ |
|||
/** |
|||
* Copyright © 2016-2022 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
package org.thingsboard.server.common.data.util; |
|||
|
|||
import java.lang.annotation.Annotation; |
|||
|
|||
@SuppressWarnings("unchecked") |
|||
public class ReflectionUtils { |
|||
|
|||
private ReflectionUtils() {} |
|||
|
|||
public static <T> T getAnnotationProperty(String targetType, String annotationType, String property) throws Exception { |
|||
Class<Annotation> annotationClass = (Class<Annotation>) Class.forName(annotationType); |
|||
Annotation annotation = Class.forName(targetType).getAnnotation(annotationClass); |
|||
return (T) annotationClass.getDeclaredMethod(property).invoke(annotation); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,53 @@ |
|||
/** |
|||
* Copyright © 2016-2022 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
package org.thingsboard.server.dao.entity; |
|||
|
|||
import org.springframework.context.ApplicationContext; |
|||
import org.springframework.stereotype.Service; |
|||
import org.thingsboard.server.common.data.EntityType; |
|||
|
|||
import javax.annotation.PostConstruct; |
|||
import java.util.HashMap; |
|||
import java.util.Map; |
|||
|
|||
@Service |
|||
public class DefaultEntityServiceRegistry implements EntityServiceRegistry { |
|||
|
|||
private final ApplicationContext applicationContext; |
|||
private final Map<EntityType, EntityDaoService> entityDaoServicesMap; |
|||
|
|||
public DefaultEntityServiceRegistry(ApplicationContext applicationContext) { |
|||
this.applicationContext = applicationContext; |
|||
this.entityDaoServicesMap = new HashMap<>(); |
|||
} |
|||
|
|||
@PostConstruct |
|||
public void init() { |
|||
applicationContext.getBeansOfType(EntityDaoService.class).values().forEach(entityDaoService -> { |
|||
EntityType entityType = entityDaoService.getEntityType(); |
|||
entityDaoServicesMap.put(entityType, entityDaoService); |
|||
if (EntityType.RULE_CHAIN.equals(entityType)) { |
|||
entityDaoServicesMap.put(EntityType.RULE_NODE, entityDaoService); |
|||
} |
|||
}); |
|||
} |
|||
|
|||
@Override |
|||
public EntityDaoService getServiceByEntityType(EntityType entityType) { |
|||
return entityDaoServicesMap.get(entityType); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,28 @@ |
|||
/** |
|||
* Copyright © 2016-2022 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
package org.thingsboard.server.msa; |
|||
|
|||
import java.lang.annotation.ElementType; |
|||
import java.lang.annotation.Retention; |
|||
import java.lang.annotation.RetentionPolicy; |
|||
import java.lang.annotation.Target; |
|||
|
|||
@Retention(RetentionPolicy.RUNTIME) |
|||
@Target({ElementType.TYPE}) |
|||
public @interface DisableUIListeners { |
|||
|
|||
} |
|||
|
|||
@ -0,0 +1,85 @@ |
|||
/** |
|||
* Copyright © 2016-2022 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
package org.thingsboard.server.msa; |
|||
|
|||
import com.google.common.io.Files; |
|||
import io.qameta.allure.Attachment; |
|||
import lombok.SneakyThrows; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.apache.commons.io.FileUtils; |
|||
import org.junit.jupiter.api.AfterEach; |
|||
import org.junit.jupiter.api.BeforeEach; |
|||
import org.junit.jupiter.api.Test; |
|||
import org.openqa.selenium.Dimension; |
|||
import org.openqa.selenium.OutputType; |
|||
import org.openqa.selenium.TakesScreenshot; |
|||
import org.openqa.selenium.WebDriver; |
|||
import org.openqa.selenium.chrome.ChromeOptions; |
|||
import org.openqa.selenium.remote.LocalFileDetector; |
|||
import org.openqa.selenium.remote.RemoteWebDriver; |
|||
|
|||
import java.io.File; |
|||
import java.net.MalformedURLException; |
|||
import java.net.URL; |
|||
|
|||
@Slf4j |
|||
public class SeleniumRemoteWebDriverTest { |
|||
|
|||
static final int WIDTH = 1680; |
|||
static final int HEIGHT = 1050; |
|||
final Dimension dimension = new Dimension(WIDTH, HEIGHT); |
|||
WebDriver driver; |
|||
|
|||
@SneakyThrows |
|||
@Attachment(value = "Page screenshot", type = "image/png") |
|||
public static byte[] captureScreen(WebDriver driver, String dirPath) { |
|||
File screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); |
|||
FileUtils.copyFile(screenshot, new File("./target/allure-results/screenshots/" + dirPath + "//" + screenshot.getName())); |
|||
return Files.toByteArray(screenshot); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* Requirement: |
|||
* docker run --name=chrome --rm --network=host -p 4444:4444 -p 7900:7900 --shm-size="2g" -e SE_NODE_MAX_SESSIONS=8 -e SE_NODE_OVERRIDE_MAX_SESSIONS=true -e SE_NODE_SESSION_TIMEOUT=90 -e SE_SCREEN_WIDTH=1920 -e SE_SCREEN_HEIGHT=1080 -e SE_SCREEN_DEPTH=24 -e SE_SCREEN_DPI=74 selenium/standalone-chrome |
|||
* */ |
|||
@BeforeEach |
|||
void setUp() throws MalformedURLException { |
|||
log.info("Requirement:"); |
|||
log.info("docker run --name=chrome --rm --network=host -p 4444:4444 -p 7900:7900 --shm-size=\"2g\" -e SE_NODE_MAX_SESSIONS=8 -e SE_NODE_OVERRIDE_MAX_SESSIONS=true -e SE_NODE_SESSION_TIMEOUT=90 -e SE_SCREEN_WIDTH=1920 -e SE_SCREEN_HEIGHT=1080 -e SE_SCREEN_DEPTH=24 -e SE_SCREEN_DPI=74 selenium/standalone-chrome"); |
|||
log.info("*----------------------* Setup driver *----------------------*"); |
|||
ChromeOptions options = new ChromeOptions(); |
|||
RemoteWebDriver remoteWebDriver = new RemoteWebDriver(new URL("http://127.0.0.1:4444"), options); |
|||
remoteWebDriver.setFileDetector(new LocalFileDetector()); |
|||
driver = remoteWebDriver; |
|||
driver.manage().window().setSize(dimension); |
|||
} |
|||
|
|||
@AfterEach |
|||
void tearDown() { |
|||
log.info("*----------------------* Teardown *----------------------*"); |
|||
driver.quit(); |
|||
} |
|||
|
|||
@Test |
|||
void testSeleniumConnection() { |
|||
driver.get("https://thingsboard.io/"); |
|||
captureScreen(driver, "success"); |
|||
log.info("Check the screenshot on target/allure-results/screenshots/success/screenshot???????????????.png"); |
|||
//Thread.sleep(TimeUnit.SECONDS.toMillis(30));
|
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,143 @@ |
|||
/** |
|||
* Copyright © 2016-2022 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
package org.thingsboard.server.msa.ui.base; |
|||
|
|||
import lombok.SneakyThrows; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.openqa.selenium.By; |
|||
import org.openqa.selenium.WebDriver; |
|||
import org.openqa.selenium.WebDriverException; |
|||
import org.openqa.selenium.WebElement; |
|||
import org.openqa.selenium.interactions.Actions; |
|||
import org.openqa.selenium.support.ui.ExpectedConditions; |
|||
import org.openqa.selenium.support.ui.WebDriverWait; |
|||
|
|||
import java.time.Duration; |
|||
import java.util.ArrayList; |
|||
import java.util.List; |
|||
import java.util.Random; |
|||
|
|||
@Slf4j |
|||
abstract public class AbstractBasePage { |
|||
protected WebDriver driver; |
|||
protected WebDriverWait wait; |
|||
protected Actions actions; |
|||
|
|||
public AbstractBasePage(WebDriver driver) { |
|||
this.driver = driver; |
|||
this.wait = new WebDriverWait(driver, Duration.ofMillis(5000)); |
|||
this.actions = new Actions(driver); |
|||
} |
|||
|
|||
@SneakyThrows |
|||
protected static void sleep(double second) { |
|||
Thread.sleep((long) (second * 1000L)); |
|||
} |
|||
|
|||
protected WebElement waitUntilVisibilityOfElementLocated(String locator) { |
|||
try { |
|||
return wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(locator))); |
|||
} catch (WebDriverException e) { |
|||
log.error("No visibility element: " + locator); |
|||
return null; |
|||
} |
|||
} |
|||
|
|||
protected WebElement waitUntilElementToBeClickable(String locator) { |
|||
try { |
|||
return wait.until(ExpectedConditions.elementToBeClickable(By.xpath(locator))); |
|||
} catch (WebDriverException e) { |
|||
log.error("No clickable element: " + locator); |
|||
return null; |
|||
} |
|||
} |
|||
|
|||
protected List<WebElement> waitUntilVisibilityOfElementsLocated(String locator) { |
|||
try { |
|||
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(locator))); |
|||
return driver.findElements(By.xpath(locator)); |
|||
} catch (WebDriverException e) { |
|||
log.error("No visibility elements: " + locator); |
|||
return null; |
|||
} |
|||
} |
|||
|
|||
protected List<WebElement> waitUntilElementsToBeClickable(String locator) { |
|||
try { |
|||
wait.until(ExpectedConditions.elementToBeClickable(By.xpath(locator))); |
|||
return driver.findElements(By.xpath(locator)); |
|||
} catch (WebDriverException e) { |
|||
log.error("No clickable elements: " + locator); |
|||
return null; |
|||
} |
|||
} |
|||
|
|||
public void waitUntilUrlContainsText(String urlPath) { |
|||
try { |
|||
wait.until(ExpectedConditions.urlContains(urlPath)); |
|||
} catch (WebDriverException e) { |
|||
log.error("This URL path is missing"); |
|||
} |
|||
} |
|||
|
|||
protected void moveCursor(WebElement element) { |
|||
actions.moveToElement(element).perform(); |
|||
} |
|||
|
|||
protected void doubleClick(WebElement element) { |
|||
actions.doubleClick(element).build().perform(); |
|||
} |
|||
|
|||
public boolean elementIsNotPresent(String locator) { |
|||
try { |
|||
return wait.until(ExpectedConditions.not(ExpectedConditions.visibilityOfElementLocated(By.xpath(locator)))); |
|||
} catch (WebDriverException e) { |
|||
throw new AssertionError("Element is present"); |
|||
} |
|||
} |
|||
|
|||
public boolean elementsIsNotPresent(String locator) { |
|||
try { |
|||
return wait.until(ExpectedConditions.not(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath(locator)))); |
|||
} catch (WebDriverException e) { |
|||
throw new AssertionError("Elements is present"); |
|||
} |
|||
} |
|||
|
|||
public void waitUntilNumberOfTabToBe(int tabNumber) { |
|||
try { |
|||
wait.until(ExpectedConditions.numberOfWindowsToBe(tabNumber)); |
|||
} catch (WebDriverException e) { |
|||
log.error("No tabs with this number"); |
|||
} |
|||
} |
|||
|
|||
public void goToNextTab(int tabNumber) { |
|||
waitUntilNumberOfTabToBe(tabNumber); |
|||
ArrayList<String> tabs = new ArrayList<>(driver.getWindowHandles()); |
|||
driver.switchTo().window(tabs.get(tabNumber - 1)); |
|||
} |
|||
|
|||
public static long getRandomNumber() { |
|||
return System.currentTimeMillis(); |
|||
} |
|||
|
|||
public static char getRandomSymbol() { |
|||
Random rand = new Random(); |
|||
String s = "~`!@#$^&*()_+=-"; |
|||
return s.charAt(rand.nextInt(s.length())); |
|||
} |
|||
} |
|||
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue