Why is Assert.AreEqual failing in NUnit? - nunit

"Robert" exists in the NWind database. The following C# code fails in NUnit:
public void Robert_exists()
{
EmployeeBO empl = new EmployeeBO();
Boolean result = empl.DoesEmployeeRecordExists("Robert");
Assert.AreEqual(true, result);
}
But single stepping shows that "result" is "true"
I would be grateful for any advice.

If it is debugging that result is true, then this should work. However, as a test, you can try using the Assert.IsTrue(result); method?

Related

Npgql get_HasRows() throwing ArgumentOutOfRangeException

Good afternoon,
I`m currently developing with AspNetCore and MVC and using PostgreSQL (Npgsql) as my database.
My queries are working fine when they have some result.
When the query returns empty results, I got an ArgumentOutOfRangeException error.
System.ArgumentOutOfRangeException: Argument is out of range.
Parameter name: Got unexpected message type: ReadyForQuery
in Npgsql.NpgsqlDataReader.get_HasRows()
in QueryPostgreSQL.IsEmpty()
in sistema_cotacao.Controllers.LoginController.<Index>d__2.MoveNext() in \Visual Studio 2015\Projects\sistema-cotacao\src\sistema-cotacao\Controllers\LoginController.cs:line 66
This is the code where the error occurs (At query.IsEmpty()):
if ((query.IsEmpty()) || (usuario.enti_email != usu.enti_email))
{
...
query.Close();
return View();
}
else
{
....
query.close();
return Redirect("/Login");
}
And my IsEmpty() function is:
private NpgsqlDataReader queryPostgreSQL;
...
public Boolean IsEmpty()
{
Boolean bResult = true;
bResult = !queryPostgreSQL.HasRows;
return bResult;
}
I couldn`t find where my problem is.
This is a bug in Npgsql. The issue has been fixed and will be released in version 3.1.7 (probably later today).

Simple "count()" query with Spring Data Couchbase

I'm having a problem I don't seem to find a solution for, and it looks really odd given i've tried everything I could with the official Spring Data Couchbase documentation.
Basically all i'm trying to do is a simple count() method.
My Repository :
public interface ICourrierRepository extends CrudRepository<Courrier, String> {
List<Courrier> findByCategorie(String categorie);
Long countByCategorie(String categorie);
#View(designDocument = "_design/courrier", viewName = "courrierBase")
long count();
}
The view is setup like this : http://img15.hostingpics.net/pics/169793Capture.png
And the view map is like this :
function (doc, meta) {
if (doc._class == "com.model.Courrier") {
emit(meta.id, null);
}
}
Worst thing is it actually works when i set a "reduce" to "_count" in the CouchBase GUI, but when I launch it from my client, I always get the same message, and the return is 0 :
[cb-computations-2] INFO c.c.c.java.view.ViewRetryHandler - Received a View HTTP response code (400) I did not expect, not retrying.
Thanks for any help...
I actually found the problem... it comes from this line :
#View(designDocument = "_design/courrier", viewName = "courrierBase")
which should be
#View(designDocument = "courrier", viewName = "courrierBase")
Also, the view should be set to reduce : _count.
Hope this helps future users !

EntityManager.createNamedQuery(...) doesn't work

I have defined a NamedNativeQuery next to a lot of NamedQueries. With NamedQueries the EntityManager.createNamedQuery(queryName) works well but when using the NamedNATIVEQuery I get an exception:
java.lang.IllegalArgumentException: NamedQuery of name: myNamedNativeQueryName not found.
The query itself works well executed in MySql Workbench but defining it as a NamedNativeQuery:
#NamedNativeQueries(value = {
#NamedNativeQuery(name = findVehicleTracksByUuidAndTimerange, query="...", resultClass=myType.class)
})
the exception occurs. I try to run the query this way:
try {
List<E> resultList = new ArrayList<E>();
javax.persistence.Query query = getEntityManager().createNamedQuery(queryName, type);
} catch(...)
What can be the reason?
As I already stated: The code from above runs well with dozens of NamedQueries...but suddenly not with the NamedNativeQuery.

Delete all messages in queue Websphere 8.5 SIB via JMX

I want to delete all the messages in a queue configured in Websphere 8.5 SIB. Below are two approaches I tried, but none of them seem to be working and each throws a different exception. Can someone please advise on what is the correct way to achieve this.
Approach 1
MBeanServerConnection connection = getServerConnection();
connection.invoke(new ObjectName("WebSphere:*,type=SIBQueuePoint,name=jms.queue.MY_QUEUE"), "deleteAllQueuedMessages", null, null);
This approach throws the below exception.
javax.management.InstanceNotFoundException: WebSphere:type=SIBQueuePoint,name=jms.queue.MY_QUEUE
Approach 2
MBeanServerConnection connection = getServerConnection();
ObjectName objQueue = new ObjectName(WAS85_RESOURCE_URL + ",type=SIBQueuePoint");
Set<ObjectName> objNames = connection.queryNames(objQueue, null);
for(ObjectName objName: objNames) {
String qName = connection.getAttribute(objName,"identifier").toString();
if(qName.equals("jms.queue.MY_QUEUE")) {
connection.invoke(objName, "deleteAllQueuedMessages", null, null);
}
}
This approach throws the below exception.
javax.management.ReflectionException: Target method not found: com.ibm.ws.sib.admin.impl.JsQueuePoint.deleteAllQueuedMessages
Figured out the issue.
The 2nd approach works. The issue was with my invocation of the deleteAllQueuedMessages message. The method takes a boolean argument which indicates the messages should be moved to the Exception Destination. I was not passing this argument !!!
I corrected the implementation as below and it works now.
connection.invoke(objName, "deleteAllQueuedMessages", new Object[]{false}, new String[]{"java.lang.Boolean"});
A better way to delete all Messages is something like that:
String queryString = "WebSphere:*,type=JMSAdministration";
ObjectName queryServer = new ObjectName(queryString);
String serverStr = "";
Set pet = aClient.queryNames(queryServer, null);
Iterator itsServer = pet.iterator();
if (itsServer.hasNext())
serverStr = itsServer.next().toString();
ObjectName obj = new ObjectName(serverStr);
Object param[] = { "jms/messageQueue","jms/messageCF" };
String signature[] = { "java.lang.String","java.lang.String" };
aClient.invoke(obj, "clear", param, signature);
Using MBean JMSAdministration is better because you can set Query exacly.

Run the JUnitServllet for integration testing in Adobe cq5

My question is for the JUnitServlet for integration testing in Adobe cq5. When it runs the tests and if there is a mistake in the test method it shows only error messages from his side. How can we see the messages that we write in the test method assertations.
For example:
If I have several "assertNotNull" in the test method and if the test fails the servlet shows me such a result:
Test finished: () : Null
I tried to enter in depth:
Test selector: RequestParser, testSelector [testClass], methodName [testMethod], extension [html]
but again it runs the whole class with thests.
Can I somehow run just one testing method from the testing class and see the messages from the assertations with this servlet? Thanks!
You might try structuring your assertions inside a try/catch block--at least initially--where you can print out additional info if it fails. I've found this to provide more useful info when I have a problem in the test itself that is getting masked in the unit test output. If that is the issue perhaps you won't need to narrow in on a single test.
#Test
public void testYourTestName() throws Exception {
try {
//Code to prepare the object to be tested
assertNull("This is my null test", objectToBeTested);
} catch (Exception e) {
String failureMessage = "\n" + e.toString() + "\n";
for (StackTraceElement stackLine : e.getStackTrace()) {
failureMessage += (stackLine.toString() + "\n");
}
fail("Error: " + failureMessage);
}
}
Or, you could use an assertEquals test which I have found to have a little more helpful display, such as this:
assertEquals(null, objectToBeTested);
If the assertEquals above fails, you get output such as this:
testMyTestName(com.myCompany.myApp.myPath.myTests): expected:<null>
but was:<java.lang.Object#5c9e4d73>
BTW, I don't know how to run just one of the tests that exists in some class, but as you have found, you can narrow it down to run all the tests in a particular class. To run the tests found in the SomeTestClass in the com.myCompany.myApp.myPath namespace:
http://localhost:4502/system/sling/junit/com.myCompany.myApp.myPath.SomeTestClass.html