From 2bed445d69d30d0b8d93741f6a94de99cca46715 Mon Sep 17 00:00:00 2001 From: Matthias Villiger Date: Wed, 26 Oct 2022 13:46:46 +0200 Subject: [PATCH] Fix tests --- .../js/JsModelValueCompletionContributor.kt | 14 +++--- .../s2i/environment/IdeaEnvironmentTest.kt | 45 ------------------- 2 files changed, 9 insertions(+), 50 deletions(-) delete mode 100644 org.eclipse.scout.sdk.s2i/src/test/kotlin/org/eclipse/scout/sdk/s2i/environment/IdeaEnvironmentTest.kt diff --git a/org.eclipse.scout.sdk.s2i/src/main/kotlin/org/eclipse/scout/sdk/s2i/template/js/JsModelValueCompletionContributor.kt b/org.eclipse.scout.sdk.s2i/src/main/kotlin/org/eclipse/scout/sdk/s2i/template/js/JsModelValueCompletionContributor.kt index 809f61a91..c2888bc57 100644 --- a/org.eclipse.scout.sdk.s2i/src/main/kotlin/org/eclipse/scout/sdk/s2i/template/js/JsModelValueCompletionContributor.kt +++ b/org.eclipse.scout.sdk.s2i/src/main/kotlin/org/eclipse/scout/sdk/s2i/template/js/JsModelValueCompletionContributor.kt @@ -74,14 +74,18 @@ class JsModelValueCompletionContributor : CompletionContributor() { } private fun withJsImportIfNecessary(lookupElement: LookupElementBuilder, place: PsiElement, jsProperty: JsModelProperty): LookupElementBuilder { - val targetScoutJsModule = jsProperty.scoutJsModule - if (!jsProperty.dataType.isCustomType() && (!targetScoutJsModule.useClassReference || (jsProperty.dataType != JsModelProperty.JsPropertyDataType.WIDGET && jsProperty.name != JsModel.OBJECT_TYPE_PROPERTY_NAME))) return lookupElement - val targetJsModel = targetScoutJsModule.jsModel - val type = if (targetScoutJsModule.useClassReference && (jsProperty.dataType == JsModelProperty.JsPropertyDataType.WIDGET || jsProperty.name == JsModel.OBJECT_TYPE_PROPERTY_NAME)) { + val scoutJsModule = jsProperty.scoutJsModule + if (!jsProperty.dataType.isCustomType() && (!scoutJsModule.useClassReference || (jsProperty.dataType != JsModelProperty.JsPropertyDataType.WIDGET && jsProperty.name != JsModel.OBJECT_TYPE_PROPERTY_NAME))) { + return lookupElement + } + + val targetJsModel = scoutJsModule.jsModel + val type = if (scoutJsModule.useClassReference && (jsProperty.dataType == JsModelProperty.JsPropertyDataType.WIDGET || jsProperty.name == JsModel.OBJECT_TYPE_PROPERTY_NAME)) { lookupElement.getUserData(SELECTED_ELEMENT) } else { targetJsModel.element(jsProperty.dataType.type) } ?: return lookupElement + val originalHandler = lookupElement.insertHandler var importName = type.name val firstDot = importName.indexOf('.') @@ -90,7 +94,7 @@ class JsModelValueCompletionContributor : CompletionContributor() { return lookupElement.withInsertHandler { context, item -> originalHandler?.handleInsert(context, item) - val targetModuleMainFile = PsiManager.getInstance(context.project).findFile(targetScoutJsModule.mainFile) ?: return@withInsertHandler + val targetModuleMainFile = PsiManager.getInstance(context.project).findFile(type.scoutJsModule.mainFile) ?: return@withInsertHandler ES6ImportPsiUtil.insertJSImport(place, importName, ES6ImportPsiUtil.ImportExportType.SPECIFIER, targetModuleMainFile, context.editor) } } diff --git a/org.eclipse.scout.sdk.s2i/src/test/kotlin/org/eclipse/scout/sdk/s2i/environment/IdeaEnvironmentTest.kt b/org.eclipse.scout.sdk.s2i/src/test/kotlin/org/eclipse/scout/sdk/s2i/environment/IdeaEnvironmentTest.kt deleted file mode 100644 index 27651ed51..000000000 --- a/org.eclipse.scout.sdk.s2i/src/test/kotlin/org/eclipse/scout/sdk/s2i/environment/IdeaEnvironmentTest.kt +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2010-2022 BSI Business Systems Integration AG. - * 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 - * https://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * BSI Business Systems Integration AG - initial API and implementation - */ -package org.eclipse.scout.sdk.s2i.environment - -import org.eclipse.scout.sdk.core.generator.type.PrimaryTypeGenerator -import org.eclipse.scout.sdk.core.log.SdkLog -import org.eclipse.scout.sdk.s2i.AbstractTestCaseWithRunningClasspathModule -import org.eclipse.scout.sdk.s2i.environment.IdeaEnvironment.Factory.callInIdeaEnvironment - - -class IdeaEnvironmentTest : AbstractTestCaseWithRunningClasspathModule() { - - fun testAsyncWriteOperationInheritsTransaction() { - callInIdeaEnvironment(project, "Test") { env, progress -> - val sourceFolder = env.toScoutJavaEnvironment(module)?.primarySourceFolder()?.orElse(null) ?: throw IllegalArgumentException("Could not find primary testing source folder") - val generator = PrimaryTypeGenerator.create() - .withElementName("Test") - .withPackageName("a.b.c") - env.writeCompilationUnitAsync(generator, sourceFolder, progress).awaitDoneThrowingOnError() - - assertEquals(1, TransactionManager.current().size()) // written compilation unit is registered in transaction of main thread - }.awaitDoneThrowingOnError() - waitForWorkerThreadsFinished() - } - - private fun waitForWorkerThreadsFinished() { - // IJ test runner uses ThreadTracker.checkLeak() in tearDown() to let the test fail if there are leaking threads detected. - // A thread is considered leaking if it is new (since the test start) and not parked in the pool at the end of the test. - // Sometimes this check is faster than our async worker threads are parked in the pool (even the future is already completed). - // Therefore, give the workers some time (after the future completion) to be parked in the pool. - try { - Thread.sleep(1000) - } catch (ie: InterruptedException) { - SdkLog.debug("Interrupted while waiting for workers to be parked.", ie) - } - } -} \ No newline at end of file