org.eclipse.xtext.testing.logging.LoggingTester Java Examples

The following examples show how to use org.eclipse.xtext.testing.logging.LoggingTester. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ResourceServiceProvideRegistryTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testUninstallBadProvider() {
	final IResourceServiceProvider.Provider provider = new IResourceServiceProvider.Provider() {
		@Override
		public IResourceServiceProvider get(URI uri, String contentType) {
			throw new NullPointerException();
		}
	};
	
	final IResourceServiceProvider.Registry reg = new ResourceServiceProviderRegistryImpl();
	reg.getExtensionToFactoryMap().put("foo", provider);
	
	assertEquals(1, reg.getExtensionToFactoryMap().size());
	LoggingTester.captureLogging(Level.ERROR, ResourceServiceProviderRegistryImpl.class, new Runnable() {
		@Override
		public void run() {
			assertNull(reg.getResourceServiceProvider(URI.createURI("hubba.foo")));
		}
	}).assertLogEntry("Erroneous resource service provider registered for 'hubba.foo'. Removing it from the registry.");
	
	assertEquals(0, reg.getExtensionToFactoryMap().size());
}
 
Example #2
Source File: RequestManagerTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test(timeout = 1000, expected = ExecutionException.class)
public void testRunReadCatchException() {
  final Runnable _function = () -> {
    try {
      final Function1<CancelIndicator, Object> _function_1 = (CancelIndicator it) -> {
        throw new RuntimeException();
      };
      final CompletableFuture<Object> future = this.requestManager.<Object>runRead(_function_1);
      Assert.assertEquals("Foo", future.get());
    } catch (Throwable _e) {
      throw Exceptions.sneakyThrow(_e);
    }
  };
  LoggingTester.captureLogging(Level.ALL, ReadRequest.class, _function);
  Assert.fail();
}
 
Example #3
Source File: Bug462047Test.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testNoErrors() throws Exception {
	IResourcesSetupUtil.createFile("bug462047/src/a.bug462047lang", "element CORE ref CORE.b");
	IFile file = IResourcesSetupUtil.createFile("bug462047/src/b.bug462047lang", "element b ref CORE.c");
	IResourcesSetupUtil.createFile("bug462047/src/c.bug462047lang", "element c");
	IResourcesSetupUtil.waitForBuild();
	IResourcesSetupUtil.assertNoErrorsInWorkspace();
	LoggingTester.captureLogging(Level.ERROR, BatchLinkableResource.class, ()-> {
		
		try {
			XtextEditor editor = openEditor(file);
			IXtextDocument document = editor.getDocument();
			document.readOnly((XtextResource res)->{
				EcoreUtil.resolveAll(res);
				ResourceSet resourceSet = res.getResourceSet();
				assertNull(resourceSet.getResource(URI.createURI("java:/Objects/CORE.CORE"), false));
				return null;
			});
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}).assertNoLogEntries();
}
 
Example #4
Source File: RequestManagerTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test(timeout = 1000)
public void testRunReadLogException() {
  final Runnable _function = () -> {
    final Function1<CancelIndicator, Object> _function_1 = (CancelIndicator it) -> {
      throw new RuntimeException();
    };
    final CompletableFuture<Object> future = this.requestManager.<Object>runRead(_function_1);
    try {
      future.join();
    } catch (final Throwable _t) {
      if (_t instanceof Exception) {
      } else {
        throw Exceptions.sneakyThrow(_t);
      }
    }
  };
  final LoggingTester.LogCapture logResult = LoggingTester.captureLogging(Level.ALL, ReadRequest.class, _function);
  logResult.assertLogEntry("Error during request:");
}
 
Example #5
Source File: RequestManagerTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test(timeout = 1000, expected = ExecutionException.class)
public void testRunWriteCatchException() {
  final Runnable _function = () -> {
    try {
      final Function0<Object> _function_1 = () -> {
        throw new RuntimeException();
      };
      final Function2<CancelIndicator, Object, Object> _function_2 = (CancelIndicator $0, Object $1) -> {
        return null;
      };
      final CompletableFuture<Object> future = this.requestManager.<Object, Object>runWrite(_function_1, _function_2);
      Assert.assertEquals("Foo", future.get());
    } catch (Throwable _e) {
      throw Exceptions.sneakyThrow(_e);
    }
  };
  LoggingTester.captureLogging(Level.ALL, WriteRequest.class, _function);
  Assert.fail("unreachable");
}
 
Example #6
Source File: RequestManagerTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test(timeout = 1000)
public void testRunWriteLogExceptionCancellable() {
  final Runnable _function = () -> {
    final Function0<Object> _function_1 = () -> {
      throw new RuntimeException();
    };
    final Function2<CancelIndicator, Object, Object> _function_2 = (CancelIndicator $0, Object $1) -> {
      return null;
    };
    final CompletableFuture<Object> future = this.requestManager.<Object, Object>runWrite(_function_1, _function_2);
    try {
      future.join();
    } catch (final Throwable _t) {
      if (_t instanceof Exception) {
      } else {
        throw Exceptions.sneakyThrow(_t);
      }
    }
  };
  final LoggingTester.LogCapture logResult = LoggingTester.captureLogging(Level.ALL, WriteRequest.class, _function);
  logResult.assertLogEntry("Error during request:");
}
 
Example #7
Source File: RequestManagerTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test(timeout = 1000)
public void testRunWriteLogExceptionNonCancellable() {
  final Runnable _function = () -> {
    final Function0<Object> _function_1 = () -> {
      return null;
    };
    final Function2<CancelIndicator, Object, Object> _function_2 = (CancelIndicator $0, Object $1) -> {
      throw new RuntimeException();
    };
    final CompletableFuture<Object> future = this.requestManager.<Object, Object>runWrite(_function_1, _function_2);
    try {
      future.join();
    } catch (final Throwable _t) {
      if (_t instanceof Exception) {
      } else {
        throw Exceptions.sneakyThrow(_t);
      }
    }
  };
  final LoggingTester.LogCapture logResult = LoggingTester.captureLogging(Level.ALL, WriteRequest.class, _function);
  logResult.assertLogEntry("Error during request:");
}
 
Example #8
Source File: JarReflectionTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void testBug470767() {
	LoggingTester.captureLogging(Level.ERROR, ReflectionTypeFactory.class, new Runnable() {
		@Override
		public void run() {
			JarReflectionTypeProviderTest.super.testBug470767();
		}
	}).assertLogEntry("Incomplete nested types for org.eclipse.xtext.common.types.testSetups.Bug470767");
}
 
Example #9
Source File: Bug281990Test.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testRecursionErrorMessage() throws Exception {
	LogCapture loggings = LoggingTester.captureLogging(Level.ERROR, LazyLinkingResource.class, new Runnable() {
		@Override
		public void run() {
			try {
				EObject model = getModelAndExpect("type Foo extends Foo.bar { Foo foo; }", 2);
				assertTrue(((Model)model).getTypes().get(0).getParentId().eIsProxy());
				assertTrue(model.eResource().getErrors().get(0).getMessage().contains("Couldn't"));
			} catch (Exception e) {
				throw Exceptions.sneakyThrow(e);
			}
		}
	});
	loggings.assertNumberOfLogEntries(1);
}
 
Example #10
Source File: AbstractReaderTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testLoadMatchNone() throws Exception {
	final Reader reader = getReader();
	reader.addPath(pathTo("emptyFolder"));
	reader.addPath(pathTo("nonemptyFolder"));
	reader.addRegister(new IndexTestLanguageStandaloneSetup());

	SlotEntry entry = createSlotEntry();
	entry.setType("Type");
	reader.addLoad(entry);
	
	reader.setUriFilter(new UriFilter() {
		@Override
		public boolean matches(URI uri) {
			return false;
		}
	});
	final WorkflowContext ctx = ctx();
	LoggingTester.captureLogging(Level.WARN, SlotEntry.class, new Runnable() {

		@Override
		public void run() {
			reader.invoke(ctx, monitor(), issues());
		}
		
	}).assertLogEntry("Could not find any exported element of type 'Type' -> Slot 'model' is empty.");
	Collection<?> slotContent = (Collection<?>) ctx.get("model");
	assertNotNull(slotContent);
	assertTrue(slotContent.isEmpty());
}
 
Example #11
Source File: TestBatchCompiler.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testActiveAnnotatons1() {
  this.batchCompiler.setSourcePath("./batch-compiler-data/activeAnnotations1");
  final Runnable _function = () -> {
    Assert.assertFalse(this.batchCompiler.compile());
  };
  final LoggingTester.LogCapture logs = LoggingTester.captureLogging(Level.ERROR, XtendBatchCompiler.class, _function);
  logs.assertNumberOfLogEntries(1);
}
 
Example #12
Source File: TestBatchCompiler.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testInvalidConfiguration_2() {
  boolean _startsWith = System.getProperty("os.name").startsWith("Windows");
  if (_startsWith) {
    final Runnable _function = () -> {
      this.batchCompiler.setSourcePath(TestBatchCompiler.XTEND_SRC_DIRECTORY);
      String _upperCase = TestBatchCompiler.XTEND_SRC_DIRECTORY.toUpperCase();
      String _plus = (_upperCase + "/xtend-gen");
      this.batchCompiler.setOutputPath(_plus);
      this.batchCompiler.compile();
    };
    final LoggingTester.LogCapture log = LoggingTester.captureLogging(Level.ERROR, XtendBatchCompiler.class, _function);
    log.assertLogEntry("xtend", "cannot be a child");
  }
}
 
Example #13
Source File: TestBatchCompiler.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testInvalidConfiguration() {
  final Runnable _function = () -> {
    this.batchCompiler.setSourcePath(TestBatchCompiler.XTEND_SRC_DIRECTORY);
    this.batchCompiler.setOutputPath((TestBatchCompiler.XTEND_SRC_DIRECTORY + "/xtend-gen"));
    this.batchCompiler.compile();
  };
  final LoggingTester.LogCapture log = LoggingTester.captureLogging(Level.ERROR, XtendBatchCompiler.class, _function);
  log.assertLogEntry("xtend", "cannot be a child");
}
 
Example #14
Source File: Storage2UriMapperJdtImplTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testBug463258_05() throws Exception {
	IJavaProject project = createJavaProject("foo");
	final Storage2UriMapperJavaImpl impl = getStorage2UriMapper();
	IPackageFragmentRoot root = project.getPackageFragmentRoot("does/not/exist.jar");
	IPackageFragment foo = root.getPackageFragment("foo");
	final JarEntryFile fileInJar = new JarEntryFile("bar.notindexed");
	fileInJar.setParent(foo);
	LoggingTester.captureLogging(Level.ERROR, Storage2UriMapperJavaImpl.class, new Runnable() {
		@Override
		public void run() {
			URI uri = impl.getUri(fileInJar);
			assertNull(uri);
		}
	}).assertNoLogEntries();
}
 
Example #15
Source File: JarClasspathTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testBug470767_02() {
	LoggingTester.captureLogging(Level.ERROR, DeclaredTypeFactory.class, new Runnable() {
		@Override
		public void run() {
			String typeName = Bug470767.class.getName();
			JvmDeclaredType type = (JvmDeclaredType) getTypeProvider().findTypeByName(typeName);
			assertEquals(1, Iterables.size(type.getAllNestedTypes()));
		}
		
	}).assertNoLogEntries();
}
 
Example #16
Source File: JarReflectionTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testBug470767_02() {
	LoggingTester.captureLogging(Level.ERROR, ReflectionTypeFactory.class, new Runnable() {
		@Override
		public void run() {
			String typeName = Bug470767.class.getName();
			JvmDeclaredType type = (JvmDeclaredType) getTypeProvider().findTypeByName(typeName);
			assertTrue(Iterables.isEmpty(type.getAllNestedTypes()));
		}
	}).assertLogEntry("Incomplete nested types for org.eclipse.xtext.common.types.testSetups.Bug470767");
}
 
Example #17
Source File: JvmTypesBuilderTest.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
protected void expectErrorLogging(final int numberOfloggings, final Runnable block) {
  final LoggingTester.LogCapture loggings = LoggingTester.captureLogging(Level.ERROR, JvmTypesBuilder.class, block);
  loggings.assertNumberOfLogEntries(numberOfloggings);
}
 
Example #18
Source File: CrossRefTest.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Test public void testGetMultiValuedLinkText() throws Exception {
	with(LazyLinkingTestLanguageStandaloneSetup.class);
	crossRefSerializer =  get(ICrossReferenceSerializer.class);
	final LazyLinkingTestLanguageGrammarAccess g =  (LazyLinkingTestLanguageGrammarAccess) get(IGrammarAccess.class);
	
	final XtextResource r = CrossRefTest.this.getResourceFromStringAndExpect("type TypeA {} type TypeB { TypeA TypeC TypeB p1; }", 1);
	LogCapture log = LoggingTester.captureLogging(Level.ERROR, LazyLinkingResource.class, new Runnable() {
		@Override
		public void run() {
			Model model = (Model) r.getContents().get(0);
			assertEquals(2, model.getTypes().size());
			
			org.eclipse.xtext.linking.lazy.lazyLinking.Type type = model.getTypes().get(1);
			assertEquals("TypeB", type.getName());
			assertEquals(1, type.getProperties().size());
	
			Property prop = type.getProperties().get(0);
			assertEquals("p1", prop.getName());
			assertEquals(3, prop.getType().size());
	
			org.eclipse.xtext.linking.lazy.lazyLinking.Type propType = prop.getType().get(0);
			assertFalse(propType.eIsProxy());
			String linkText = crossRefSerializer.serializeCrossRef(prop,g.getPropertyAccess().getTypeTypeCrossReference_0_0(), propType, null);
			assertEquals("TypeA", linkText);
	
			propType = prop.getType().get(1);
			assertTrue(propType.eIsProxy());
			INode node = getCrossReferenceNode(prop, GrammarUtil.getReference(g.getPropertyAccess().getTypeTypeCrossReference_0_0()), propType);
			linkText = crossRefSerializer.serializeCrossRef(prop,g.getPropertyAccess().getTypeTypeCrossReference_0_0(), propType, node);
			assertEquals("TypeC", linkText);
	
			propType = prop.getType().get(2);
			assertFalse(propType.eIsProxy());
			node = getCrossReferenceNode(prop, GrammarUtil.getReference(g.getPropertyAccess().getTypeTypeCrossReference_0_0()), propType);
			linkText = crossRefSerializer.serializeCrossRef(prop,g.getPropertyAccess().getTypeTypeCrossReference_0_0(), propType, null);
			assertEquals("TypeB", linkText);
	
			Adapter adapter = (Adapter) NodeModelUtils.getNode(prop);
			prop.eAdapters().remove(adapter);
			propType = prop.getType().get(1);
			assertTrue(propType.eIsProxy());
			linkText = crossRefSerializer.serializeCrossRef(prop,g.getPropertyAccess().getTypeTypeCrossReference_0_0(), propType, null);
			assertNull(linkText);
		}
	});
	log.assertNumberOfLogEntries(2);
}